1. coloring manual
1) geom_point, geom_line, etc.
grouping with color for discrete value
g <- ggplot(data = df)
g + geom_point(aes(x = var1, y = var2, color = 'discrete variable name')) +
geom_line(aes(x= var1, y = var2, color = 'discrete variable name'))+
scale_color_manual('legend title', breaks = 'discrete variable name', values = 'color value')
# when drawing more than one point or line, breaks = c(), values = c()
grouping with color for continuous value
g <- ggplot(data = df)
g + geom_point(aes(x = var1, y = var2, color = 'continuous variable name')) +
geom_line(aes(x= var1, y = var2, color = 'continuous variable name'))+
scale_color_continuous('legend title', low = 'color for low value', high = 'color for high value')
# scale_color_continuous can be exchanged with scale_color_gradient or scale_color_gradientn( n step gradient )
2) geom_bar, geom_hist, etc.
# almost same as above
... + scale_fill_manual('legend title', breaks = 'discrete variable name', values = 'color value')
# for coloring with discrete variable
... + scale_fill_continuous('legend title', low = 'color for low value', high = 'color for high value')
# for coloring with continuous variable
'Programming' 카테고리의 다른 글
가상환경을 위해 WSL(windows subsystem for Linux) 깔아보기 (0) | 2020.05.06 |
---|---|
html, css 가운데 정렬 총 정리 (0) | 2020.04.11 |
[R] Efficient R programming practice (0) | 2018.12.16 |
[R] ggplot error message (0) | 2018.12.06 |
[R] ggplot basic item (0) | 2018.12.06 |