gpt4 book ai didi

r - 轴标签在 ggplot2 中消失了

转载 作者:行者123 更新时间:2023-12-04 07:40:43 27 4
gpt4 key购买 nike

谁能发现为什么我在 ggplot2 中制作的这个图表上看不到轴刻度线?
enter image description here


(
df%>%
ggplot(aes(x=daysincubated4, y=emission_mean))+
labs(color = "", size= "") +
labs(x = "Incubation time (days)", y = "Production (nmol g-1 dw soil h-1)") +
facet_wrap(vars(compound), scales = "free_y") +
geom_rect(xmin = -2, xmax = 3, ymin = 0, ymax = 80,
fill="lightblue3",alpha = 1.0)+
geom_rect(xmin = 3, xmax = 69, ymin = 0, ymax = 80,
fill = "lightcoral", alpha = 1.0) +
geom_rect(xmin = 69, xmax = 120, ymin = 0, ymax = 80,
fill="lightyellow2",alpha = 1.0) +
geom_rect(aes(xmin = -2, xmax = 3, ymin = 0, ymax = 80,
fill="lightblue3"),alpha = 1.0)+
geom_rect(aes(xmin = 3, xmax = 69, ymin = 0, ymax = 80,
fill = "lightcoral"), alpha = 1.0) +
geom_rect(aes(xmin = 69, xmax = 120, ymin = 0, ymax = 80,
fill="lightyellow2"),alpha = 1.0)+
geom_pointrange(aes(x = daysincubated4, y = emission_mean, ymin = emission_mean, ymax = emission_mean + se,
color = category, shape = category, group = category, size=category)) +
scale_color_manual(name = "", labels = c("Period Mean", "Emission"),
values = c("dark", "black")) +
scale_shape_manual(name = "", labels = c("Period Mean", "Emission"), values = c(17, 19))+
scale_size_manual(name = "", labels = c("Period Mean", "Emission"), values = c(0.7, 0.5))+
scale_fill_manual(name = "", labels = c("Thaw", "Anoxic","Oxic"), values = c("lightblue3", "lightcoral","lightyellow2"))+
tidytext::scale_x_reordered(expand = c(0,0))+
scale_y_discrete(expand = c(0,0))+
theme_bw()
)

df <- structure(list(compound = c("Acetaldehyde", "Acetaldehyde", "Acetone",
"Acetone", "Acetaldehyde", "Acetaldehyde", "Acetone", "Acetone",
"Acetaldehyde", "Acetaldehyde", "Acetaldehyde", "Acetaldehyde",
"Acetaldehyde", "Acetone", "Acetone", "Acetone", "Acetone", "Acetone",
"Acetaldehyde", "Acetaldehyde", "Acetaldehyde", "Acetone", "Acetone",
"Acetone", "Acetaldehyde", "Acetone"), daysincubated4 = c(33,
95, 33, 95, 33, 95, 33, 95, 4, 10, 17, 24, 66, 4, 10, 17, 24,
66, 81, 94, 116, 81, 94, 116, 0, 0), emission_mean = c(24.5,
0.4, 35.8, 2.8, 24.5, 0.4, 35.8, 2.8, 59.1, 45, 11.4, 6.7, 0.1,
46.7, 44, 56.7, 29.1, 2.7, 0, 0.5, 0.6, 7.7, 0.4, 0.2, 26.1,
28.5), se = c(11.6, 0.2, 9.4, 2.5, 11.6, 0.2, 9.4, 2.5, 11, 11.4,
4.3, 3.5, 0, 9, 9.9, 22.8, 13.8, 1.2, 0, 0.2, 0.3, 6.4, 0.1,
0.1, 5.9, 7.4), sampling_period = structure(c(2L, 3L, 2L, 3L,
2L, 3L, 2L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L,
3L, 3L, 3L, 3L, 1L, 1L), .Label = c("Thaw", "Anoxic", "Oxic"), class = "factor"),
category = c("mean", "mean", "mean", "mean", "mean", "mean",
"mean", "mean", "single", "single", "single", "single", "single",
"single", "single", "single", "single", "single", "single",
"single", "single", "single", "single", "single", "single",
"single")), row.names = c(NA, -26L), class = "data.frame")

最佳答案

当您更改为 scale_y_continuous(expand = c(0,0)) 时,您将恢复 y 轴刻度。因为它是一个连续的尺度。 x 轴刻度消失,因为 tidytext::scale_x_reordered(expand = c(0,0))通常组合使用 reorder_within对于因素,但在我看来,您的比例在这里也是连续的。

df%>%
ggplot(aes(x=daysincubated4, y=emission_mean))+
#labs(color = "", size= "") +
labs(x = "Incubation time (days)", y = "Production (nmol g-1 dw soil h-1)") +
facet_wrap(vars(compound), scales = "free_y") +
geom_rect(xmin = -2, xmax = 3, ymin = 0, ymax = 80,
fill="lightblue3",alpha = 1.0)+
geom_rect(xmin = 3, xmax = 69, ymin = 0, ymax = 80,
fill = "lightcoral", alpha = 1.0) +
geom_rect(xmin = 69, xmax = 120, ymin = 0, ymax = 80,
fill="lightyellow2",alpha = 1.0) +
geom_rect(aes(xmin = -2, xmax = 3, ymin = 0, ymax = 80,
fill="lightblue3"),alpha = 1.0)+
geom_rect(aes(xmin = 3, xmax = 69, ymin = 0, ymax = 80,
fill = "lightcoral"), alpha = 1.0) +
geom_rect(aes(xmin = 69, xmax = 120, ymin = 0, ymax = 80,
fill="lightyellow2"),alpha = 1.0)+
geom_pointrange(aes(x = daysincubated4, y = emission_mean, ymin = emission_mean, ymax = emission_mean + se,
color = category, shape = category, group = category, size=category)) +
scale_color_manual(name = "", labels = c("Period Mean", "Emission"),
values = c("dark", "black")) +
scale_shape_manual(name = "", labels = c("Period Mean", "Emission"), values = c(17, 19))+
scale_size_manual(name = "", labels = c("Period Mean", "Emission"), values = c(0.7, 0.5))+
scale_fill_manual(name = "", labels = c("Thaw", "Anoxic","Oxic"), values = c("lightblue3", "lightcoral","lightyellow2"))+
scale_x_continuous(expand = c(0,0))+
scale_y_continuous(expand = c(0,0))+
theme_bw()

关于r - 轴标签在 ggplot2 中消失了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67482249/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com