本文用到的数据为R语言自带的mtcars
,为了演示,将vs
这一变量设置为了因子型。
mtcars.copy = mtcars
mtcars.copy$vs = as.factor(mtcars.copy$vs)
用如下代码可以绘制一张基础ggplot2
的散点图:横坐标为mpg
,纵坐标为wt
,颜色为vs
(两个值)。
ggplot(data = mtcars.copy)+
geom_point(aes(x = mpg,y = wt, color = vs, shape = vs))
我们修改后的结果为(各项解释请向下翻):
i=1
ggplot(data = mtcars.copy)+
geom_point(aes(x = mpg,y = wt, color = vs, shape = vs, ),
size = 3) +
labs(title = bquote('This is figure '*.(i)),
x = 'Weight (1000 lbs)',
y = "