这是我第一次在这个论坛上发帖寻求帮助,所以如果我做错了什么,请接受我的道歉。
我正在尝试使用圆形图绘制以下数据。我对完成圆圈的数据有问题所以我为角度365添加了一个额外的值,这给我带来了标记为月份的问题,因为你会注意到图中的“Jan /”。我还想用不同的灰色阴影遮蔽值10和30的环。
任何帮助将不胜感激!
干杯,
圆形图
我的数据集
angle freq Month LH
0 20 Jan a
30 16 Feb a
60 19 Mar a
90 17 Apr a
120 15 May a
150 27 Jun a
180 40 Jul a
210 42 Aug a
240 37 Sep a
270 32 Oct a
310 33 Nov a
330 17 Dec a
365 23.5 a
0 38 Jan b
30 42 Feb b
60 40 Mar b
90 31 Apr b
120 32 May b
150 24 Jun b
180 17 Jul b
210 17 Aug b
240 18 Sep b
270 19 Oct b
310 14 Nov b
330 23 Dec b
365 43.5 b
0 16 Jan c
30 18 Feb c
60 18 Mar c
90 14 Apr c
120 28 May c
150 41 Jun c
180 39 Jul c
210 39 Aug c
240 30 Sep c
270 36 Oct c
310 23 Nov c
330 13 Dec c
365 20.5 c
我的代码
df <- read.csv("data.csv")
vol <- ggplot(df, aes(x = angle, y = freq, linetype = LH, size = LH, fill = LH)) +
coord_polar(theta = "x", start = -pi/365) +
geom_smooth(method = loess, se = FALSE, colour = "black") +
scale_linetype_manual(values = c("solid", "longdash", "dotted")) +
scale_size_manual(values = c(1, 1, 1))
vol <- vol +
scale_x_continuous(breaks = c(0, 30, 60, 90, 120, 150,
180, 210, 240, 270, 300, 330, 365),
labels = c("Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", ""))
vol <- vol + scale_y_continuous(limits = c(0, 45), breaks = c(0, 10, 20, 30, 40))
vol <- vol + annotate("text", x=0, y=12, label="10", size=4, face="bold", family="Arial")
vol <- vol + annotate("text", x=0, y=22, label="20", size=4, face="bold", family="Arial")
vol <- vol + annotate("text", x=0, y=32, label="30", size=4, face="bold", family="Arial")
vol <- vol + annotate("text", x=0, y=42, label="40", size=4, face="bold", family="Arial")
vol <- vol + theme_bw() +
theme(panel.border = element_rect(linetype = "solid", colour = "black", size = 1))
vol <- vol +
theme(text = element_text(face = "bold", size = 16, family = "Tahoma"),
panel.grid.major = element_line(linetype = "solid", colour = "grey45")) +
theme(legend.position = "none")
vol <- vol + xlab("") + ylab("")
vol <- vol + theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank())
vol
答案 0 :(得分:0)
您的问题分为两部分。我将尝试单独解决它们:
不要添加365 /&#34;&#34;作为scale_x_continuous
中的符号/标签的值。
使用geom_hline
&amp;指定每行所需的颜色。在极坐标下,水平线将环绕形成环。
可以使您的代码/图表更易于阅读的其他小问题:
size = 1
所有行,则无需在size = LH
内指定aes()
。theme(...)
规格放在一个地方。通过这种方式跟踪它们会更容易。多个文本注释也是如此。这是一个实现:
ggplot(df,
aes(x = angle, y = freq, linetype = LH)) +
geom_smooth(method = "loess", se = FALSE, colour = "black") +
geom_hline(yintercept = 30, colour = "grey55", size = 2) +
geom_hline(yintercept = 10, colour = "grey75", size = 2) +
annotate("text",
x = 0, y = c(12, 22, 32, 42),
label = c("10", "20", "30", "40"),
size = 4) +
coord_polar() +
scale_x_continuous(breaks = seq(0, 11) * 30, labels = month.abb) +
scale_y_continuous(limits = c(0, 45), breaks = seq(0, 4) * 10) +
scale_linetype_manual(values = c("solid", "longdash", "dotted")) +
theme_void() +
theme(panel.border = element_rect(size = 1, fill = NA),
panel.grid.major = element_line(colour = "lightgrey"),
legend.position = "none",
axis.text = element_text(face = "bold", size = 16),
axis.text.y = element_blank())