본문 바로가기
공부/R Programming

R기초; R 기초 - ggplot2 그래픽6 - 그래프 배치 및 저장

by 혼밥맨 2021. 1. 24.
반응형

R기초; R 기초 - ggplot2 그래픽6 - 그래프 배치 및 저장

 

library(ggplot2)

libray(car)

str(Salaries)

 

ggplot(Salaries, aes(x=rank)) + 

        geom_bar(fill="steelblue")

 

ggplot(Salaries, aes(x=salary)) +

         geom_histogram(fill="maroon")

 

ggplot(Salaries, aes(x=yrs.since.phd, y=salary)) +

         geom_point(color="orange")

 

ggplot(Salaries, aes(x=rank, y=salary)) +

         geom_boxplot(fill="mistyrose")

 

install.packages("gridExtra")

library(gridExtra)

grid.arrange()

 

p1 <- ggplot(Salaries, aes(x=rank)) +

        geom_bar(fill="steelblue")

 

p2 <- ggplot(Salaries, aes(x=salary)) +

         geom_histogram(fill="maroon")

 

p3 <- ggplot(Salaries, aes(x=yrs.since.phd, y=salary)) +

         geom_point(color="orange")

 

p4 <- ggplot(Salaries, aes(x=rank, y=salary)) +

         geom_boxplot(fill="mistyrose")

 

grid.arrange(p1, p2, p3, p4, nrow=2, ncol=2)

 

myggplot <- grid.arrange(p1, p2, p3, p4, nrow=2, ncol=2)

ggsave(file="myplot.png", plot=myggplot, width=7.0, height=5.5)

 

??ggsave

 

ggplot(Salaries, aes(x=rank, y=salary)) +

         geom_boxplot()

 

ggsave(file="myplo2.png")

 

 

반응형

댓글