我在R中缺少一些基础知识。
如何为数据框中的每一列绘制曲线图?
我试着分别为每一列绘制图。我想知道有没有更简单的方法?
library(dplyr)
library(ggplot2)
data(economics)
#scatter plots
ggplot(economics,aes(x=pop,y=pce))+
geom_point()
ggplot(economics,aes(x=pop,y=psavert))+
geom_point()
ggplot(economics,aes(x=pop,y=uempmed))+
geom_point()
ggplot(economics,aes(x=pop,y=unemploy))+
geom_point()
#boxplots
ggplot(economics,aes(y=pce))+
geom_boxplot()
ggplot(economics,aes(y=pop))+
geom_boxplot()
ggplot(economics,aes(y=psavert))+
geom_boxplot()
ggplot(economics,aes(y=uempmed))+
geom_boxplot()
ggplot(economics,aes(y=unemploy))+
geom_boxplot()所有我正在寻找的是有一个盒子图2*2和1 2*2散点图与ggplot2。我知道有一个刻面网格,我不知道如何实现它。(我相信这可以通过par(mfrow())和base R图轻松实现。我在其他地方看到使用加宽数据?我不明白。
发布于 2019-11-12 20:28:05
在这种情况下,解决方案几乎总是reshape the data from wide to long format。
economics %>%
select(-date) %>%
tidyr::gather(variable, value, -pop) %>%
ggplot(aes(x = pop, y = value)) +
geom_point(size = 0.5) +
facet_wrap(~ variable, scales = "free_y")
economics %>%
tidyr::gather(variable, value, -date) %>%
ggplot(aes(y = value)) +
geom_boxplot() +
facet_wrap(~ variable, scales = "free_y")https://stackoverflow.com/questions/58818300
复制相似问题