英文:
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 <- 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)
答案1
得分: 2
以下是您要翻译的内容:
这可能不是您想要的。这是使用rAmCharts4包完成的。
library(rAmCharts4)
gradingData <- data.frame(
label = c("Bottom", "Top"),
color = c("lightblue", "darkblue"),
lowScore = c(0, 15),
highScore = c(15, 100)
)
amGaugeChart(
score = 37, minScore = 0, maxScore = 100, gradingData = gradingData,
hand = amHand(innerRadius = 40, width = 15, color = "red", strokeColor = "black")
)
您可以将"bottom"和"top"替换为百分比。
英文:
Not sure this is what you want. This is done with the rAmCharts4 package.
library(rAmCharts4)
gradingData <- data.frame(
label = c("Bottom", "Top"),
color = c("lightblue", "darkblue"),
lowScore = c(0, 15),
highScore = c(15, 100)
)
amGaugeChart(
score = 37, minScore = 0, maxScore = 100, gradingData = gradingData,
hand = amHand(innerRadius = 40, width = 15, color = "red", strokeColor = "black")
)
You can replace "bottom" and "top" by the percentages.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论