馅饼阴谋得到它的文本在彼此顶部 [英] Pie plot getting its text on top of each other
本文介绍了馅饼阴谋得到它的文本在彼此顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
试图解决这个重叠的标签:
我的代码:
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 =图形$ 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),color =#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,color = NA))
print(pie)
尝试用星号(** **)标记的值,但没有任何地方。
任何帮助表示赞赏。
解决方案
这是一个例子:
pie < - ggplot(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)
也许这会帮助你理解它是如何工作的:
pie + coord_polar(theta =y)+
geom_text(aes(y = seq(1,sum(values $ val),length = 10),label = letters [1:10]))
Just trying to fix this overlapped labeling:
My code:
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)
Tried messing with the values marked with asterisks (** **) but haven't got anywhere. Any help appreciated.
解决方案
here is an example:
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")
Perhaps this will help you understand how it work:
pie + coord_polar(theta = "y") +
geom_text(aes(y = seq(1, sum(values$val), length = 10), label = letters[1:10]))
这篇关于馅饼阴谋得到它的文本在彼此顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文