【发布时间】:2017-01-12 00:44:30
【问题描述】:
我想在阿基米德螺旋上创建一个条形图,就像讨论过的 here。
最终目标类似于this,但不那么压倒性。
这是一个示例数据框:
test <- structure(list(month = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12),
year = c(2015, 2015, 2015, 2015, 2015, 2015, 2015,
2015, 2015, 2015, 2015, 2015, 2016, 2016,
2016, 2016, 2016, 2016, 2016, 2016, 2016,
2016, 2016, 2016),
value = c(49, 34, 35, 34, 50, 35, 48, 50, 44, 38, 42,
43, 33,30, 42, 43, 58, 55, 47, 36, 35, 53,
61, 59)),
.Names = c("month", "year", "value"),
class = "data.frame", row.names = c(NA, -24L))
我可以使用以下代码制作条形图:
ggplot(monthly, aes(x = ym, y = value)) +
geom_bar(stat = "identity")
我可以使用以下代码制作螺旋:
a <- 0 #Any number here & it still looks the same to me...
b <- 10 #Any number here & it still looks the same to me...
theta <- seq(0,10*pi, 0.01)
r <- a + b*theta
df <- data.frame(x = r*cos(theta), y = r*sin(theta))
ggplot(df, aes(x,y)) +
geom_point(col = 'red')
但我如何(如果有的话)在螺旋上绘制条形?
这与我得到的差不多:使用 my 数据而不是上述公式创建螺旋。但是我的数据实际上并没有显示出来......
d <- ggplot(monthly, aes(x = month, y = month, color = year)) +
geom_path(size = 2) +
coord_polar() +
theme_minimal() +
theme(legend.position = "none")
d
【问题讨论】:
标签: r ggplot2 polar-coordinates spiral