R 使用expand=c(0,0)时,沿x轴的标签将消失
我有一个关于x轴标签的问题。假设我有以下情节:R 使用expand=c(0,0)时,沿x轴的标签将消失,r,ggplot2,graphic,R,Ggplot2,Graphic,我有一个关于x轴标签的问题。假设我有以下情节: p <- ggplot(long_form_q, aes(reihe, variable)) + geom_tile(aes(fill = value), colour = "white") pneu <- p + scale_fill_gradient(low = "white",high = "steelblue", limits= c(1,3), breaks=c(1,2,3)) + geom_text(aes(labe
p <- ggplot(long_form_q, aes(reihe, variable)) + geom_tile(aes(fill = value), colour = "white")
pneu <- p + scale_fill_gradient(low = "white",high = "steelblue", limits= c(1,3), breaks=c(1,2,3)) +
geom_text(aes(label=long_form_textq$value)) +
theme(axis.title.x = element_blank(),axis.title.y =element_blank()) +
theme(axis.text.y = element_text(size=18, color = "black"), axis.text.x = element_text(size=14)) +
scale_y_discrete(labels=c(h_3x3.1="3x3", h_3x5.1="3x5", h_3x9.1 ="3x9"), expand=c(0,0))
标签消失了
我的dput
是:
dput(long_form_q)
structure(list(reihe = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L), variable = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("h_3x3.1",
"h_3x5.1", "h_3x9.1"), class = "factor"), value = c(1, 1, 1,
2, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 1,
3, 3, 3, 3, 3, 3)), row.names = c(NA, -30L), .Names = c("reihe",
"variable", "value"), class = "data.frame")
您正在沿x轴绘制连续数据,因此正确的比例为
scale\u x\u continuous()
。标签消失的原因是您错误地使用了scale\u x\u discrete()
pneu您正在沿x轴绘制连续数据,因此正确的比例是scale\u x\u continuous()
。标签消失的原因是您错误地使用了scale\u x\u discrete()
pneuscale\u x_离散(breaks=c(1,2,3,4,5,6,7,8,9,10),labels=c(“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”),expand=c(0,0))
。请参见编辑我的数据的dputlong\u form\u textq$value
?这个数据集怎么样?scale\u x\u discrete(breaks=c(1,2,3,4,5,6,7,8,9,10),labels=c(“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”),expand=c(0,0))
如果我们有数据,它会更容易,但类似的东西应该可以工作。不,轴消失了。请参见编辑我的数据的dputlong\u form\u textq$value
?这个数据集怎么样?
dput(long_form_q)
structure(list(reihe = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L,
10L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 1L, 2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L), variable = structure(c(1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("h_3x3.1",
"h_3x5.1", "h_3x9.1"), class = "factor"), value = c(1, 1, 1,
2, 1, 1, 1, 1, 1, 1, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 1,
3, 3, 3, 3, 3, 3)), row.names = c(NA, -30L), .Names = c("reihe",
"variable", "value"), class = "data.frame")
pneu <- p + scale_fill_gradient(low = "white",high = "steelblue", limits= c(1,3), breaks=c(1,2,3)) +
geom_text(aes(label=value)) +
theme(axis.title.x = element_blank(),axis.title.y =element_blank()) +
theme(axis.text.y = element_text(size=18, color = "black"), axis.text.x = element_text(size=14)) +
scale_y_discrete(labels=c(h_3x3.1="3x3", h_3x5.1="3x5", h_3x9.1 ="3x9"),
expand=c(0, 0)) +
scale_x_continuous(expand = c(0, 0), breaks = 1:10)
pneu