半圆环图与数值

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

Half donut chart with values

问题

I have translated the code portion as requested:

  1. # Verwijder alle vorige objecten
  2. rm(list = ls())
  3. library(ggplot2)
  4. # Dummy data voor de chart
  5. data <- data.frame(
  6. categorie = c("Categorie 1", "Categorie 2"),
  7. waarde = c(0.85, 0.15)
  8. )
  9. # Kleuren per deel
  10. kleuren <- c("#468bcc", '#cae6f2') # donker en lichtblauw
  11. # Pijl locatie
  12. arrow = 0.37
  13. # Berekeningen voor de halve cirkel
  14. total <- sum(data$waarde)
  15. data$percentage <- data$waarde / total
  16. data$start <- cumsum(data$percentage) - data$percentage
  17. data$einde <- cumsum(data$percentage)
  18. # Maak de plot
  19. plot <- ggplot(data, aes(x = 1, y = waarde, fill = categorie)) +
  20. geom_rect(aes(xmin = 1, xmax = 2, ymin = start, ymax = einde * 2), color = NA) +
  21. geom_segment(aes(x = 1, y = arrow, xend = 2, yend = arrow), color = "red", size = 1) +
  22. coord_polar(theta = "y", start = 0) + # Draai de figuur niet
  23. xlim(0.5, 2.5) +
  24. theme_void() +
  25. theme(legend.position = "none")
  26. # Voeg zwarte lijnen toe bij 0 en 100 graden
  27. plot <- plot +
  28. geom_segment(aes(x = 1, y = 0, xend = 2, yend = 0), color = "black", size = 1) +
  29. geom_segment(aes(x = 1, y = 1, xend = 2, yend = 1), color = "black", size = 1)
  30. # Pas de kleuren van de delen aan
  31. plot <- plot + scale_fill_manual(values = kleuren)
  32. # Plot de halve cirkel donut chart
  33. 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 半圆环图与数值

  1. # Verwijder alle vorige objecten
  2. rm(list = ls())
  3. library(ggplot2)
  4. # Dummy data voor de chart
  5. data &lt;- data.frame(
  6. categorie = c(&quot;Categorie 1&quot;, &quot;Categorie 2&quot;),
  7. waarde = c(0.85, 0.15)
  8. )
  9. # Kleuren per deel
  10. kleuren &lt;- c(&quot;#468bcc&quot;, &#39;#cae6f2&#39;) # donker en lichtblauw
  11. # Pijl locatie
  12. arrow = 0.37
  13. # Berekeningen voor de halve cirkel
  14. total &lt;- sum(data$waarde)
  15. data$percentage &lt;- data$waarde / total
  16. data$start &lt;- cumsum(data$percentage) - data$percentage
  17. data$einde &lt;- cumsum(data$percentage)
  18. # Maak de plot
  19. plot &lt;- ggplot(data, aes(x = 1, y = waarde, fill = categorie)) +
  20. geom_rect(aes(xmin = 1, xmax = 2, ymin = start, ymax = einde * 2), color = NA) +
  21. geom_segment(aes(x = 1, y = arrow, xend = 2, yend = arrow), color = &quot;red&quot;, size = 1) +
  22. coord_polar(theta = &quot;y&quot;, start = 0) + # Draai de figuur niet
  23. xlim(0.5, 2.5) +
  24. theme_void() +
  25. theme(legend.position = &quot;none&quot;)
  26. # Voeg zwarte lijnen toe bij 0 en 100 graden
  27. plot &lt;- plot +
  28. geom_segment(aes(x = 1, y = 0, xend = 2, yend = 0), color = &quot;black&quot;, size = 1) +
  29. geom_segment(aes(x = 1, y = 1, xend = 2, yend = 1), color = &quot;black&quot;, size = 1)
  30. # Pas de kleuren van de delen aan
  31. plot &lt;- plot + scale_fill_manual(values = kleuren)
  32. # Plot de halve cirkel donut chart
  33. print(plot)

答案1

得分: 2

以下是您要翻译的内容:

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

  1. library(rAmCharts4)
  2. gradingData &lt;- data.frame(
  3. label = c(&quot;Bottom&quot;, &quot;Top&quot;),
  4. color = c(&quot;lightblue&quot;, &quot;darkblue&quot;),
  5. lowScore = c(0, 15),
  6. highScore = c(15, 100)
  7. )
  8. amGaugeChart(
  9. score = 37, minScore = 0, maxScore = 100, gradingData = gradingData,
  10. hand = amHand(innerRadius = 40, width = 15, color = &quot;red&quot;, strokeColor = &quot;black&quot;)
  11. )

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

英文:

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

  1. library(rAmCharts4)
  2. gradingData &lt;- data.frame(
  3. label = c(&quot;Bottom&quot;, &quot;Top&quot;),
  4. color = c(&quot;lightblue&quot;, &quot;darkblue&quot;),
  5. lowScore = c(0, 15),
  6. highScore = c(15, 100)
  7. )
  8. amGaugeChart(
  9. score = 37, minScore = 0, maxScore = 100, gradingData = gradingData,
  10. hand = amHand(innerRadius = 40, width = 15, color = &quot;red&quot;, strokeColor = &quot;black&quot;)
  11. )

半圆环图与数值

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:

确定