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

标签 r ggplot2

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

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/

相关文章:

r - 使用read.zoo代替read.table和zoo()?

r - 如何根据R中其他列的数据有条件地执行减法?

r - 使用 ggplot2 : Create faceted scatterplot with scaled and moved density

R - 使用 ggplot2 在 x 轴上绘制儒略日

r - ggplot 中的颜色编码和图例标签

R:在数据框的多列上使用 cor.test

r - 计算 R 中疾病的首次出现次数

r - R 中数字和字符列的 dcast - 默认返回长度

r - 是否有一种编程方式可以在 ggplot2 图上传递 y 轴的特定范围?

r - ggplot2 : don't connect dots if gap in time