gpt4 book ai didi

r - 如何在ggplot2中使用coord_polar移动x轴标签

转载 作者:行者123 更新时间:2023-12-01 13:44:37 26 4
gpt4 key购买 nike

我无法在下图中移动轴标签(字段数据、辅助数据等),使它们既大又完全适合图表。整个代码如下。关于做什么的建议?

Coord_polar figure

Datasource<-c("Field data", "Participatory data", "Remotely sensed data", 
"Remotely sensed secondary data", "Secondary data")
Number<-c(32,39,55,96,202)
Percentage<-c(11,14,19,34,70)
DF<-data.frame(Datasource, Number, Percentage)

FigDataSourcesFlower<-ggplot(data=DF, aes(x=Datasource, y=Percentage)) +
geom_bar(stat="identity", fill = "blue") + theme_bw() +
geom_text(aes(y = Percentage + 2.5,label = Percentage)) +
coord_polar() +
theme(axis.text.x = element_text(size = 15), axis.text.y=element_blank(), axis.ticks=element_blank(), axis.title=element_blank())
FigDataSourcesFlower

我尝试使用 hjustvjust ,但我不认为这正是我正在寻找的,因为这些更多用于角度调整。我读到我可能可以使用 \n将标签分成两行,希望这有助于它们适合,但我不确定如何做到这一点。

最佳答案

这是我目前能做的最好的事情:

p<-ggplot(data=DF, aes(x=Datasource, y=Percentage)) +
geom_bar(stat="identity", fill = "blue") +
geom_text(aes(y = Percentage + 2.5,label = Percentage)) +
coord_polar() +
theme_bw() +
theme(axis.text.x = element_text(size = 15),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
axis.title=element_blank(),
panel.border = element_blank())
p

library(grid)
gt <- ggplot_gtable(ggplot_build(p))
gt$layout$clip[gt$layout$name == "panel"] <- "off"
grid.draw(gt)

这个想法来自 this回答。

关于r - 如何在ggplot2中使用coord_polar移动x轴标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36916773/

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