半圆环图与数值

huangapple go评论66阅读模式
英文:

Half donut chart with values

问题

I have translated the code portion as requested:

# Verwijder alle vorige objecten
rm(list = ls())

library(ggplot2)

# Dummy data voor de chart
data <- data.frame(
  categorie = c("Categorie 1", "Categorie 2"),
  waarde = c(0.85, 0.15)
)

# Kleuren per deel
kleuren <- c("#468bcc", '#cae6f2')  # donker en lichtblauw

# Pijl locatie
arrow = 0.37

# Berekeningen voor de halve cirkel
total <- sum(data$waarde)
data$percentage <- data$waarde / total
data$start <- cumsum(data$percentage) - data$percentage
data$einde <- cumsum(data$percentage)

# Maak de plot
plot <- ggplot(data, aes(x = 1, y = waarde, fill = categorie)) +
  geom_rect(aes(xmin = 1, xmax = 2, ymin = start, ymax = einde * 2), color = NA) +
  geom_segment(aes(x = 1, y = arrow, xend = 2, yend = arrow), color = "red", size = 1) +
  coord_polar(theta = "y", start = 0) +  # Draai de figuur niet
  xlim(0.5, 2.5) +
  theme_void() +
  theme(legend.position = "none")

# Voeg zwarte lijnen toe bij 0 en 100 graden
plot <- plot +
  geom_segment(aes(x = 1, y = 0, xend = 2, yend = 0), color = "black", size = 1) +
  geom_segment(aes(x = 1, y = 1, xend = 2, yend = 1), color = "black", size = 1)

# Pas de kleuren van de delen aan
plot <- plot + scale_fill_manual(values = kleuren)

# Plot de halve cirkel donut chart
print(plot)

Is there anything else you would like to know or translate?

英文:

This is how it looks right now

I have this code in R, but it makes a "donut" however I want to create half a donut. With the information at the top with 85% in dark blue and 15% in light blue with a red line at 37%. But whatever I do I cannot get ride of the blue part on the left side of the black line.

Moreover, it would be totally perfect if there where text labels also mentioning the 85%,15% and 37 %

People are Saying I need to switch back to Excel but I want to proof it is possible in R too 半圆环图与数值

# Verwijder alle vorige objecten
rm(list = ls())

library(ggplot2)

# Dummy data voor de chart
data &lt;- data.frame(
  categorie = c(&quot;Categorie 1&quot;, &quot;Categorie 2&quot;),
  waarde = c(0.85, 0.15)
)

# Kleuren per deel
kleuren &lt;- c(&quot;#468bcc&quot;, &#39;#cae6f2&#39;)  # donker en lichtblauw

# Pijl locatie
arrow = 0.37

# Berekeningen voor de halve cirkel
total &lt;- sum(data$waarde)
data$percentage &lt;- data$waarde / total
data$start &lt;- cumsum(data$percentage) - data$percentage
data$einde &lt;- cumsum(data$percentage)

# Maak de plot
plot &lt;- ggplot(data, aes(x = 1, y = waarde, fill = categorie)) +
  geom_rect(aes(xmin = 1, xmax = 2, ymin = start, ymax = einde * 2), color = NA) +
  geom_segment(aes(x = 1, y = arrow, xend = 2, yend = arrow), color = &quot;red&quot;, size = 1) +
  coord_polar(theta = &quot;y&quot;, start = 0) +  # Draai de figuur niet
  xlim(0.5, 2.5) +
  theme_void() +
  theme(legend.position = &quot;none&quot;)

# Voeg zwarte lijnen toe bij 0 en 100 graden
plot &lt;- plot +
  geom_segment(aes(x = 1, y = 0, xend = 2, yend = 0), color = &quot;black&quot;, size = 1) +
  geom_segment(aes(x = 1, y = 1, xend = 2, yend = 1), color = &quot;black&quot;, size = 1)

# Pas de kleuren van de delen aan
plot &lt;- plot + scale_fill_manual(values = kleuren)

# Plot de halve cirkel donut chart
print(plot)

答案1

得分: 2

以下是您要翻译的内容:

这可能不是您想要的。这是使用rAmCharts4包完成的。

library(rAmCharts4)

gradingData &lt;- data.frame(
  label = c(&quot;Bottom&quot;, &quot;Top&quot;),
  color = c(&quot;lightblue&quot;, &quot;darkblue&quot;),
  lowScore = c(0, 15),
  highScore = c(15, 100)
)

amGaugeChart(
  score = 37, minScore = 0, maxScore = 100, gradingData = gradingData,
  hand = amHand(innerRadius = 40, width = 15, color = &quot;red&quot;, strokeColor = &quot;black&quot;)
)

您可以将"bottom"和"top"替换为百分比。

英文:

Not sure this is what you want. This is done with the rAmCharts4 package.

library(rAmCharts4)

gradingData &lt;- data.frame(
  label = c(&quot;Bottom&quot;, &quot;Top&quot;),
  color = c(&quot;lightblue&quot;, &quot;darkblue&quot;),
  lowScore = c(0, 15),
  highScore = c(15, 100)
)

amGaugeChart(
  score = 37, minScore = 0, maxScore = 100, gradingData = gradingData,
  hand = amHand(innerRadius = 40, width = 15, color = &quot;red&quot;, strokeColor = &quot;black&quot;)
)

半圆环图与数值

You can replace "bottom" and "top" by the percentages.

huangapple
  • 本文由 发表于 2023年6月8日 19:40:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/76431497.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定