ggplot text

Published by onesixx on

http://www.sthda.com/english/articles/32-r-graphics-essentials/125-ggplot-cheat-sheet-for-great-customization

Title & Axis name

labs

Tooth <- ToothGrowth %>% setDT()
Tooth[ , `:=`(dose=as.factor(dose))]

boxP <- Tooth %>% ggplot(aes(x=dose, y=len)) + geom_boxplot(aes(color=dose)) +
  				scale_color_manual(values=c("red", "green", "blue"))
R
R

Axis Labels & breaks

scale_x_, theme

scatterP  <- cars %>% ggplot(aes(speed, dist)) + geom_point()
R
fl <- nycflights13::flights
dd <- with(fl, data.table(daytime=make_datetime(year, month, day, hour, minute, 0),
					                value= sched_arr_time))
dd <- dd[order(daytime), ][,value:=mean(value), by=daytime]
delayP <- dd[1:500,] %>% ggplot(aes(daytime, value)) + geom_path() + geom_point() 
R
passenger <- tsbox::ts_dt(AirPassengers)
timeP <- passenger %>% ggplot(aes(time, value)) + geom_path()
R

text annotation(주석)

  • geom_text(), geom_label()
  • annotate()
crimes <- USArrests %>% setDT(keep.rownames=T)
crimesP <- crimes %>% ggplot(aes(x=UrbanPop, y=Murder)) + geom_point()
R
scatterP  <- cars %>% ggplot(aes(speed, dist)) + geom_point()
R
Categories: ggplot2

onesixx

Blog Owner

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x