ggplot2-点图

简介: ggplot2-点图

p <- ggplot(mtcars, aes(wt, mpg))

p + geom_point()

# Add aesthetic mappings

p + geom_point(aes(colour = qsec))

p + geom_point(aes(alpha = qsec))

p + geom_point(aes(colour = factor(cyl)))

p + geom_point(aes(shape = factor(cyl)))

p + geom_point(aes(size = qsec))

# Change scales

p + geom_point(aes(colour = cyl)) + scale_colour_gradient(low = "blue")

p + geom_point(aes(size = qsec)) + scale_area()

p + geom_point(aes(shape = factor(cyl))) + scale_shape(solid = FALSE)

# Set aesthetics to fixed value

p + geom_point(colour = "red", size = 3)

qplot(wt, mpg, data = mtcars, colour = I("red"), size = I(3))

# You can create interesting shapes by layering multiple points of

# different sizes

p <- ggplot(mtcars, aes(mpg, wt))

p + geom_point(colour="grey50", size = 4) + geom_point(aes(colour = cyl))

p + aes(shape = factor(cyl)) +

geom_point(aes(colour = factor(cyl)), size = 4) +

geom_point(colour="grey90", size = 1.5)

p + geom_point(colour="black", size = 4.5) +

geom_point(colour="pink", size = 4) +

geom_point(aes(shape = factor(cyl)))

# These extra layers don't usually appear in the legend, but we can

# force their inclusion

p + geom_point(colour="black", size = 4.5, show_guide = TRUE) +

geom_point(colour="pink", size = 4, show_guide = TRUE) +

geom_point(aes(shape = factor(cyl)))

相关文章
|
6月前
ggplot2如何在R语言中绘制表格
ggplot2如何在R语言中绘制表格
75Echarts - 散点图(Large Scatter)
75Echarts - 散点图(Large Scatter)
32 0
|
编解码 数据可视化 数据挖掘
R语言之 ggplot 2 和其他图形
R语言之 ggplot 2 和其他图形
97 0
|
数据可视化 API 图形学
ggplot
ggplot是一个基于Python的数据可视化库,灵感来自于R语言中的ggplot2库。它提供了一种语法简洁、灵活而强大的方式来创建各种类型的统计图表。
199 0
|
数据建模
R绘图-ggplot2 (2)
R绘图-ggplot2 (2)
|
数据挖掘
ggplot2|从0开始绘制直方图
ggplot2|从0开始绘制直方图
301 0
|
人工智能 搜索推荐 数据处理
ggplot2|玩转Manhattan图-你有被要求这么画吗?
ggplot2|玩转Manhattan图-你有被要求这么画吗?
246 0
|
数据挖掘
ggplot2|从0开始绘制折线图
ggplot2|从0开始绘制折线图
161 0