0

我正在尝试创建一个图表,我对它几乎很满意。我只想更改 x 轴的限制(对数刻度)。我试图在 scale_x_continuous 中设置限制,但这会导致一条直线,而不是十条 S 曲线。到目前为止,我的代码是:

library("ggplot2")
ggplot(evaporation, aes(x = evaporation$h)) +
  geom_line(aes(y = C1_theta, color = "blue"), size = 1.1) +
  geom_line(aes(y = C2_theta, color = "blue"), size = 1.1) +
  geom_line(aes(y = C3_theta, color = "blue"), size = 1.1) +
  geom_line(aes(y = C4_theta, color = "blue"), size = 1.1) +
  geom_line(aes(y = C5_theta, color = "blue"), size = 1.1) +
  geom_line(aes(y = S1_theta, color = "green"), size = 1.1) +
  geom_line(aes(y = S2_theta, color = "green"), size = 1.1) +
  geom_line(aes(y = S3_theta, color = "green"), size = 1.1) +
  geom_line(aes(y = S4_theta, color = "green"), size = 1.1) +
  geom_line(aes(y = S5_theta, color = "green"), size = 1.1) +
  scale_x_continuous(trans = "log", breaks = c(0, 10, 100, 1000, 10000, 100000), limits = 0, 100000) +
  theme_bw() +
  labs(y = expression(theta ~ (cm^3/cm^3)), x = "Absolute Pressure Head h (cm)") +
  scale_color_manual(name = "Samples",
                     labels = c("Control sample", "Treated sample"),
                     values = c("#4472C4", "#70AD47")) +
  theme(legend.position = c(0.82, 0.72), legend.direction = "vertical", legend.background = element_rect(colour = "black", linetype = "solid"))

有谁知道如何确保 x 轴停在 100000 处?

4

1 回答 1

0

所以有两个选项,@teunbrand 表示的第一个选项是将限制设置为 c(NA, 1000000)。它看起来像:

scale_x_continuous(trans = "log", breaks = c(0, 10, 100, 1000, 10000, 100000), limits = c(NA, 100000))

检查括号和“c”。

第二个选项是从 scale_x_continuous 中删除限制,而是使用

xlim()

它看起来像:

scale_x_continuous(trans = "log", breaks = c(0, 10, 100, 1000, 10000, 100000)) +
xlim(0, 100000)
于 2021-02-13T14:46:51.897 回答