R语言与医学统计图形-【10】ggplot2图形映射

ggplot2绘图系统——图形映射

颜色的映射。

#aes中映射变量
ggplot()+geom_point(aes(x=carat,y=price,color='blue'),#color视为单一变量
                    data=dsmall)
#映射外的颜色
ggplot()+geom_point(aes(x=carat,y=price),
                    data=dsmall,color='blue')

image.png
image.png

#加I函数后,不管位置
#同样适用于fill/alpha/size/shape等属性
ggplot()+geom_point(aes(x=carat,y=price,color=I('blue')),
                    data=dsmall)
ggplot()+geom_point(aes(x=carat,y=price),
                    data=dsmall,color=I('blue'))

image.png

填充映射。

#fill映射
k <- ggplot(mtcars,aes(factor(cyl),fill=factor(vs)))
k+geom_bar()

image.png

大小的映射。

#映射大小
ggplot(mtcars,aes(wt,mpg))+
  geom_point(aes(color=factor(cyl),size=drat))

#固定大小
ggplot(mtcars,aes(wt,mpg))+
  geom_point(aes(color=factor(cyl)),size=4)

image.pngimage.png

形状的映射。

ggplot(mtcars,aes(wt,mpg))+
  geom_point(aes(shape=factor(cyl)),color='orange',size=4)

image.png

原文地址:https://www.cnblogs.com/jessepeng/p/12307696.html