我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 年的標簽是如此接近,以至于在視覺上很難將它們解釋為時鐘的開始和停止。有沒有辦法增加它們之間的間距?(見下面的示例圖片)
我一直在嘗試使用theme(axis.text.x = ...)上面評論的方式進行自定義,但到目前為止它并沒有達到我想要的效果。還有其他建議嗎?謝謝!

uj5u.com熱心網友回復:
您可以簡單地調整 x 軸上的中斷和標簽。我認為它還可以改善帶有彎曲標簽的外觀,也許還有一些年份分隔符:
library(geomtextpath)
ggplot(d, aes(year, cover, color = species))
geom_rect(data = data.frame(y = c(2017, 2017 2/3, 2018 1/3)),
aes(ymax = Inf, ymin = -Inf, xmin = y, xmax = y 2/3),
inherit.aes = FALSE, alpha = 0.05, color = "gray75")
geom_line(size = 2)
coord_curvedpolar()
theme_classic()
scale_x_continuous(breaks = c(2017.33, 2018, 2018.67), labels = 2017:2019)
theme(text = element_text(size = 18),
legend.text = element_text(face = "italic"),
legend.title=element_blank(),
legend.position="right",
axis.line.x.bottom = element_blank())

uj5u.com熱心網友回復:
使用注釋可能更容易?
ggplot(d, aes(year, cover, color = species))
geom_line(size = 2)
annotate("text", size = 6, label = year,
x = c(2017.1, 2018, 2018.9),
y = c(110, 90, 110))
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(labels = NULL)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/482172.html
上一篇:來自r-graph-gallery的圓形條形圖出現錯誤:“美學必須是長度1...”
下一篇:如何通過多個變數重新排序條形圖
