R: 关于 ggplot2 的初探

生活还很长,别急,慢慢来。亲爱的

require(ggplot2)
p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point() ; p1
p1 + scale_x_continuous("Engine displacement (L)") + scale_y_continuous("Highway MPG")

p1 + scale_x_continuous(limits = c(2, 6))
p1 + scale_x_continuous(limits = c(0, 10))
p1 + scale_x_continuous(breaks = c(2, 4, 6))
p1 + scale_x_continuous(breaks = c(2, 4, 6),label = c("two", "four", "six"))

p1 + scale_y_log10()
p1 + scale_y_sqrt()
p1 + scale_y_reverse()
p1 + scale_y_continuous(trans = scales::reciprocal_trans())

df <- data.frame(x = rnorm(10) * 100000,y = seq(0, 1, length.out = 10))
p2 <- ggplot(df, aes(x, y)) + geom_point(); p2
p2 + scale_y_continuous(labels = scales::percent)
p2 + scale_y_continuous(labels = scales::dollar)
p2 + scale_x_continuous(labels = scales::comma)

posted @ 2018-05-19 23:57  number_5  阅读(179)  评论(0编辑  收藏  举报