- 直方图
单个直方图:
mycol <- c("#377EB8","#FF7F00","#4DAF4A") #定义颜色变量
p0 <- ggplot(data=dt1,aes(x=index1))+
geom_histogram(fill = mycol[1],position = 'identity',colour = "black",binwidth = 8,alpha = .6) +#binwidth分组宽度
labs(
title = "总指数-直方图",
x = NULL,
y = NULL
)+
theme_economist();p0
分类直方图
p1 <- ggplot(data=dt1,aes(x=index1))+
geom_histogram(aes(fill = city) ,position = 'identity',colour = "black",binwidth = 8,alpha = .6) +#binwidth分组宽度
labs(
title = "总指数-直方图",
x = NULL,
y = NULL
)+
theme_economist();p1
2. 密度曲线
p2 <- ggplot(data=dt1,aes(x=index1))+
geom_density(size = 1,aes(colour = city))+
labs(
title = "总指数-正态密度曲线",
x = NULL,
y = NULL
)+
theme_economist();p2
3. 二维密度曲线
p3 <- ggplot(data=dt1,aes(x=s3,y=index1))+
geom_point() +
geom_density2d()+
labs(
title = "总指数-年龄等高线",
x = NULL,
y = NULL
)+
theme_economist();p3
4. 散点图+拟合曲线
p4 <- ggplot(data=dt1,aes(x=s3,y=index1))+
geom_point() +
geom_smooth();p4
5. 气泡图
col_gray <- gray(c(2,5,8)/11)#定义颜色
p5 <- ggplot(data=dt1,aes(x=s3,y=index1))+
geom_point(aes(size = index1,colour=city))+
scale_colour_manual(values = col_gray);p5
6. 箱图
p6 <- ggplot(dt1,aes(x=city,y=index1,lab=index1))+
geom_boxplot(aes(fill = city));p6