[英]R ggplot: Move y axis to grid lines on polar plot (Polar_Coord)
I'm creating a polar plot showing a histogram of the direction travlled of paired group data. 我正在创建一个极坐标图,显示配对组数据移动方向的直方图。 More specifically, directions travelled between different groups of sibling. 更具体地说,方向是在不同组的兄弟姐妹之间传播的。
Here is a mock: 这是一个模拟:
mockdf <- data.frame(dir = as.numeric( runif( 1000, -pi/2, pi) ),
ID = sample(letters[1:2], 1000, TRUE))
ggplot(data=mockdf, aes(x=mockdf$dir)) +
coord_polar(theta = "x", start = pi, direction = 1) +
scale_fill_manual(name = "Sibling", values=c("black", "White")) +
geom_histogram(bins=32, aes(fill=mockdf$ID), color= "black") +
facet_wrap(~mockdf$ID) +
scale_y_continuous("Number of reloactions", limits = c(-8,30)) +
scale_x_continuous(limits = c(-pi,pi), breaks = c(0, pi/4, pi/2, 3*pi/4,
pi, -3*pi/4, -pi/2, -pi/4),
labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW"))
I'd like to move the y axis labels of 0, 10, 20, 30 onto the grid itself (ie along the SW orientation), but having difficulties doing so. 我想将0、10、20、30的y轴标签移动到网格本身上(即,沿SW方向),但是这样做很难。 Does anyone know how I go about doing this? 有人知道我该怎么做吗?
You can use options within theme
to remove current axis text and tick marks and geom_text()
to manually add the labels. 您可以在theme
使用选项来删除当前轴文本和刻度线,并使用geom_text()
手动添加标签。 I've demonstrated how to add the first one. 我已经演示了如何添加第一个。
ggplot(data=mockdf, aes(x=mockdf$dir)) +
coord_polar(theta = "x", start = pi, direction = 1) +
scale_fill_manual(name = "Sibling", values=c("black", "White")) +
geom_histogram(bins=32, aes(fill=mockdf$ID), color= "black") +
facet_wrap(~mockdf$ID) +
scale_y_continuous("Number of reloactions", limits = c(-8,30)) +
scale_x_continuous(limits = c(-pi,pi), breaks = c(0, pi/4, pi/2, 3*pi/4,
pi, -3*pi/4, -pi/2, -pi/4),
labels = c("N", "NE", "E", "SE", "S", "SW", "W", "NW")) +
# remove text and tick marks from axis
theme(axis.text.y = element_blank(),
axis.ticks.y = element_blank()) +
# add label manually
geom_text(x = 4, y = 10, label = "10")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.