R语言ggplot画图初步1

library(ggplot2)
library(gridExtra)
iris=read.csv("D:/Rdata/Windows/data/chap3/Iris.csv")
##ggplot(data,aes(x=...,y=...))#初始化一个ggplot绘图对象
##theme_**()控制图像非数据显示的内容
##geom_**()绘图方式
windowsFonts(STKaiti=windowsFont("华文楷体"))#调用windows字体
##散点图
p1=ggplot(iris,aes(x=PetalLengthCm,y=PetalWidthCm))+
  theme_bw(base_size =20,base_family="STKaiti")+
  geom_point(aes(color = Species))+labs(title = "散点图")
##小提琴图
p2=ggplot(iris,aes(x= Species,y = SepalLengthCm))+
  theme_gray(base_family = "STKaiti",base_size = 15)+
  geom_violin(aes(fill=Species),show.legend = F)+
  labs(title = "小提琴图")+
  theme(plot.title = element_text(hjust=0.9))
##密度函数
p3=ggplot(iris,aes(SepalWidthCm))+
  theme_minimal(base_family = "STKaiti",base_size = 10)+
  geom_density(aes(color=Species,fill=Species),alpha=0.5)+
  labs(title = "密度曲线")+
  theme(plot.title = element_text(hjust = 0.5),legend.position = c(0.8,0.8))
##等高线图
p4=ggplot(iris,aes(x=SepalLengthCm,y=SepalWidthCm))+
  theme_classic(base_family = "STKaiti",base_rect_size = 5)+
  geom_point(shape=17)+
  geom_density2d(linemitre = 5)+
  theme(plot.title = element_text(hjust = 0.2))+
  ggtitle("二维密度曲线")
##将4个图像放进一个图像中
grid.arrange(p1,p2,p3,p4,nrow=2)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值