在coord_polar上制作弯曲文本

时间:2016-07-05 15:33:09

标签: r dataframe ggplot2

我想用coord_polar在ggplot周围制作弯曲的文字。我有data.frame:

z <- data.frame( a=c("sensor 1","sensor 2","sensor 3","sensor 4","sensor 5","sensor 6","sensor 7","sensor 8"),  b=c(50, 60, 70, 20,90,110,30,100))

这是我创建ggplot的代码:

cxc <- ggplot(z, aes(x=a, y=b, fill=factor(b))) + 
    geom_bar(width = 1,stat="identity",colour = "black")
cxc + coord_polar() + 
  theme_linedraw() +theme(axis.ticks =element_blank(), axis.text.y =element_blank(), axis.title=element_blank(), axis.text.x=element_text(size = 12,angle = 45)) 

这是我的结果中的图像。我想要制作文本(x轴):传感器1,传感器2 ......制作弯曲,就像我从coord_polar围绕圆圈绘制红色。必须适合圆圈。 enter image description here

2 个答案:

答案 0 :(得分:8)

我不确定弯曲文字,但如果你想让它们至少旋转,这是一个开始:

myAng <-
  seq(-20,-340,length.out = 8)

cxc + coord_polar() + 
  theme_linedraw() +
  theme(axis.ticks =element_blank()
        , axis.text.y =element_blank()
        , axis.title=element_blank()
        , axis.text.x=element_text(size = 12
                                   ,angle = myAng)) 

我会毫不犹豫地使用这样的角度(甚至像这样的情节的极坐标)。但是,我认为你有充分的理由这样做,并且这个MWE只是没有显示它。

enter image description here

答案 1 :(得分:3)

我不知道如何使它们与使用ggplot2的曲线完全相同,但我们至少可以删除这个有趣的角度......

enter image description here

pm <- grid::unit(c(2, 2, 2, 2), "cm")
RadarTheme<-theme(panel.background=element_blank(),
                  plot.title= element_text(size = 25,face=c("bold","italic")),
                  plot.margin = pm,
                  text=element_text(family="Open Sans"), aspect.ratio = 1,
                  legend.position="bottom",legend.title=element_blank(),legend.direction="vertical",
                  strip.text.x = element_text(size = rel(0.8)),
                  axis.text.x = element_text(size = 15,face ="bold"),
                  axis.ticks.y = element_blank(),
                  axis.text.y = element_blank(),
                  axis.line.x=element_line(size=0.5),
                  panel.grid.major=element_line(size=0.3,linetype = 2,colour="grey"))

cxc <- ggplot(z, aes(x=a, y=b, fill=factor(b))) + 
  geom_bar(width = 1,stat="identity",colour = "black")


cxc + coord_polar() + RadarTheme