我想将 y 轴和 x 轴的位置更改为零,尽管我有负值。我在 Google 小组中读到,当时 ggplot
是不可能的。此功能从那以后开始实现了吗?
例如,当我有这个数据时
library(ggplot2)
df1 <- data.frame(
S = rep(c(10, 5, 3.3, 2.5, 1.66, 0.62), 2),
v = c(c(0.202, 0.079, 0.0597, 0.0565, 0.0365, 0.0318),
c(0.25, 0.14, 0.07, 0.06, 0.04, 0.03)),
inhibitor = rep(c("nein", "ja"), each = 6)
)
我想根据我手动添加的hline
和vline
改变坐标轴的位置。
ggplot(df1, aes(y = v, x = S, shape = inhibitor)) +
geom_point() +
xlim(c(-2, 10)) +
geom_smooth(aes(linetype = inhibitor),
method = "lm", se = FALSE,
fullrange = TRUE, color = "black") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0)
最佳答案
您是在谈论删除轴和轴标签之间的空间吗?
ggplot2 的比例函数中的 expand
参数设置绘图限制和轴之间的填充。
ggplot(df1, aes(y = v, x = S, shape = inhibitor)) +
geom_point() +
xlim(c(-2, 10)) +
geom_smooth(aes(linetype = inhibitor),
method = "lm", se = FALSE,
fullrange = TRUE, color = "black") +
geom_vline(xintercept = 0) +
geom_hline(yintercept = 0) +
scale_x_continuous(expand=c(0,0)) +
scale_y_continuous(expand=c(0,0))
关于r - ggplot : shift position of y and x axis,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55531308/