ggplot 箱线图刻面
ggplot box plot faceting
我正在使用以下代码制作 ggplot 箱线图:
p <- ggplot(data = five, mapping = aes(x = variable, y = value, fill = variable)) +
geom_boxplot(alpha = .3) +
geom_jitter(alpha = .3) +
labs(title = "Stock Data", x = "Index", y = "Percent Return") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
facet_wrap(vars(variable))
p
有没有什么办法可以把不用的x轴变量去掉白色的space?我意识到我可以制作三个单独的图表,然后将它们并排排列,但很好奇是否可以在同一张图表上完成?
scales = "free" 需要添加到 facet_wrap 参数中。
p <- ggplot(data = five, mapping = aes(x = variable, y = value, fill = variable)) +
geom_boxplot(alpha = .3) +
geom_jitter(alpha = .3) +
labs(title = "Stock Data", x = "Index", y = "Percent Return") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
facet_wrap(vars(variable), scales = "free")
p
我正在使用以下代码制作 ggplot 箱线图:
p <- ggplot(data = five, mapping = aes(x = variable, y = value, fill = variable)) +
geom_boxplot(alpha = .3) +
geom_jitter(alpha = .3) +
labs(title = "Stock Data", x = "Index", y = "Percent Return") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
facet_wrap(vars(variable))
p
有没有什么办法可以把不用的x轴变量去掉白色的space?我意识到我可以制作三个单独的图表,然后将它们并排排列,但很好奇是否可以在同一张图表上完成?
scales = "free" 需要添加到 facet_wrap 参数中。
p <- ggplot(data = five, mapping = aes(x = variable, y = value, fill = variable)) +
geom_boxplot(alpha = .3) +
geom_jitter(alpha = .3) +
labs(title = "Stock Data", x = "Index", y = "Percent Return") +
theme_bw() +
theme(plot.title = element_text(hjust = 0.5)) +
facet_wrap(vars(variable), scales = "free")
p