自定义X轴标签位置在GGPLOT中+ coord_polar
我正在使用coord_polar
将物种丰度随时间变化显示为时钟图,如下所示,
year<-c(2017, 2018, 2019) # observation dates
sp1<-c(39,55,85)
sp2 <-c(100, 75, 65)
sp3 <-c(32,57,42)
df <-data.frame(year, sp1, sp2, sp3)
d <- df %>%
pivot_longer(!year, names_to = "species", values_to = "cover")
plot <-ggplot(d, aes(year, cover, color = species)) +
geom_line(size = 2) + coord_polar() + theme_classic() +
theme(text = element_text(size = 18),
legend.text = element_text(face = "italic"),
#axis.text.x=element_blank(), # remove all x axis labels in polar_coord
#axis.text.x=element_text(angle = 25), # rotates angle, but does not increase distance between labels.
legend.title=element_blank(),
legend.position="right") +
scale_x_continuous(breaks=c(2019, 2018, 2017)) # this customizes the x-axis labels to be my
# exact observation dates. List order places 2019 at the 11:59 "clock" position,
# and 2017 at the 12:01 "clock" position)
plot
我看到的是2017年和2019年的标签是如此近,因此在视觉上很难将其解释为开始和停止时钟。有没有办法增加它们之间的间距? (请参阅下面的示例图)
我一直在尝试使用主题(axis.text.x = ...)
,如上所述进行自定义,但到目前为止,它还没有做我想要的。还有其他建议吗?谢谢!
I'm using coord_polar
to show changes in species abundance over time as a clock plot as shown below
year<-c(2017, 2018, 2019) # observation dates
sp1<-c(39,55,85)
sp2 <-c(100, 75, 65)
sp3 <-c(32,57,42)
df <-data.frame(year, sp1, sp2, sp3)
d <- df %>%
pivot_longer(!year, names_to = "species", values_to = "cover")
plot <-ggplot(d, aes(year, cover, color = species)) +
geom_line(size = 2) + coord_polar() + theme_classic() +
theme(text = element_text(size = 18),
legend.text = element_text(face = "italic"),
#axis.text.x=element_blank(), # remove all x axis labels in polar_coord
#axis.text.x=element_text(angle = 25), # rotates angle, but does not increase distance between labels.
legend.title=element_blank(),
legend.position="right") +
scale_x_continuous(breaks=c(2019, 2018, 2017)) # this customizes the x-axis labels to be my
# exact observation dates. List order places 2019 at the 11:59 "clock" position,
# and 2017 at the 12:01 "clock" position)
plot
The issue that I see is that the 2017 and 2019 labels are so close it's visually hard to interpret these as the start and stop of the clock. Is there a way to increase the spacing between them? (see example pic below)
I've been trying to use theme(axis.text.x = ...)
as commented above to customize, but so far it's not doing what I want. Any other suggestions? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以简单地调整X轴上的断裂和标签。我认为这也可以改善具有弯曲标签的外观,也许还有几年的分隔线:
You can simply adjust the breaks and labels on the x axis. I think it also improves the appearance to have curved labels and perhaps some year dividers:
注释也许更容易?
Perhaps easier with an annotation?