我正在创建一个极坐标图,显示配对组数据的方向直方图.更具体地说,在不同的兄弟群体之间旅行的方向.
这是一个模拟:
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"))
我想将0,10,20,30的y轴标签移动到网格本身上(即沿着SW方向),但是这样做有困难.有谁知道我是怎么做的?
最佳答案 您可以使用主题中的选项删除当前轴文本和刻度标记andgeom_text()以手动添加标签.我已经演示了如何添加第一个.
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")