본문 바로가기
공부/R Programming

R 기초 - ggplot2 그래픽4 - 그래프 옵션

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

R 기초 - ggplot2 그래픽4 - 그래프 옵션

library(ggplot2)

 

library(car)

str(Salaries)

 

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

          geom_boxplot() +

          scale_x_discrete(breaks=c("AsstProf", "AssocProf", "Prof"), labels=c("Assistant Professor", "Associate Professor", "Professor")) +

          scale_y_continuous(breaks=c(50000, 100000, 150000, 200000),

                                   labels=c("$50k", "$100k", "$150k", "$200k")

 

scale_x_discrete()

scale_x_continuous()

scale_y_discrete()

scale_y_continuous()

 

data(mtcars)

head(mtcars)

 

ggplot(mtcars, aes(x=wt, y=mpg, shape=factor(cyl), color=factor(cyl))) +

         geom_point() +

         labs(shape="Cylinder", color="Cylinder")

 

 

ggplot(mtcars, aes(x=wt, y=mpg, size=disp)) +

         geom_point(shape=21, color="black", fill="wheat") +

         labs(size="Engine\nDisplacement")

 

ggplot(mtcars, aes(x=wt, y=mpg, size=disp)) +

         geom_point(shape=21, color="black", fill="wheat") +

         scale_size_continuous(name="Engine\nDisplacement")

 

# 막대그래프

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

         geom_bar() + 

         scale_fill_manual(values=c("tomato", "cornflowerblue"))

 

# 산점도

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

         geom_point(size=2) + 

         scale_color_manual(values=c("orange", "violetred", "steelblue"))

 

 

?RColorBrewer

 

 

 

 

반응형

댓글