gpt4 book ai didi

r - 饼图将其文本置于彼此之上

转载 作者:行者123 更新时间:2023-12-04 10:20:32 26 4
gpt4 key购买 nike

只是试图修复这个重叠的标签:



我的代码:

  values=c(164241,179670)
labels=c("Private", "Public")
colors=c("#cccccc", "#aaaaaa")
categoriesName="Access"
percent_str <- paste(round(graph$values / sum(graph$values) * 100,1), "%", sep="")

values <- data.frame(val = graph$values, Type = graph$labels, percent=percent_str )

pie <- ggplot(values, aes(x = "", y = val, fill = Type)) + geom_bar(width = 1) +
geom_text(aes(y = **val + 1**, **hjust=0.5**, **vjust=-0.5**, label = percent), colour="#333333", face="bold", size=10) +
coord_polar(theta = "y") + ylab(NULL) + xlab(NULL) +
scale_fill_manual(values = graph$colors) + labs(fill = graph$categoriesName) +
opts( title = graph$title,
axis.text.x = NULL,
plot.margin = unit(c(0,0,0,0), "lines"),
plot.title = theme_text(face="bold", size=14),
panel.background = theme_rect(fill = "white", colour = NA) )
print(pie)

尝试弄乱标有星号 (** **) 的值,但一无所获。
任何帮助表示赞赏。

最佳答案

这是一个例子:

pie <- ggplot(values, aes(x = "", y = val, fill = Type)) + 
geom_bar(width = 1) +
geom_text(aes(y = val/2 + c(0, cumsum(val)[-length(val)]), label = percent), size=10)
pie + coord_polar(theta = "y")

enter image description here

也许这会帮助你理解它是如何工作的:
pie + coord_polar(theta = "y") + 
geom_text(aes(y = seq(1, sum(values$val), length = 10), label = letters[1:10]))

enter image description here

关于r - 饼图将其文本置于彼此之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8952077/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com