https://www.cnblogs.com/songbiao/p/12490831.html
install.packages('ggplot2', repos = "https://mirrors.tuna.tsinghua.edu.cn/CRAN/")
library(ggplot2)
year <- c(2017,2018,2022,2024)
money <- c(1018,1246,1780,2000)
plot(year,money,type="b",col="red")
df <- data.frame(Year = year,Money = money)
qplot(year,Money,data=df)
qplot(Wind,Temp,data=airquality,color=Month)
airquality$Month <- factor(airquality$Month)
qplot(Wind,Temp,data=airquality,color=Month)
qplot(Wind,Temp,data=airquality,color=I("red"))
qplot(Wind,Temp,data=airquality,shape=Month)
qplot(Wind,Temp,data=airquality,size=Month)
qplot(Wind,Temp,data=airquality,color=Month,xlab="Winds",
ylab="Temps",main = "Wind~Temp")
qplot(Wind,Temp,data=airquality,color=Month,xlab="Winds",
ylab="Temps",main = "Wind~Temp",geom = c("point","smooth"))
qplot(Wind,Temp,data=airquality,color=Month,xlab="Winds",
ylab="Temps",main = "Wind~Temp",geom = c("point","smooth"),
facets = .~Month)
ggplot(airquality,aes(Wind,Temp))+
geom_point(aes(color=factor(Month)),
alpha=0.4,size=5)
ggplot(airquality,aes(Wind,Temp))+
geom_point()+
geom_smooth()
ggplot(airquality,aes(Wind,Temp))+
geom_smooth(method = "lm",se=FALSE)
ggplot(airquality,aes(Wind,Temp))+
geom_smooth(method = "lm",se=FALSE,aes(color=Month))
ggplot(airquality,aes(Wind,Temp,col=factor(Month)))+
geom_smooth(method = "lm",se=FALSE)
ggplot(airquality,aes(Wind,Temp,col=factor(Month) ,group=1))+
geom_point()+
geom_smooth(method = "lm",se=FALSE)
ggplot(airquality,aes(Wind,Temp,col=factor(Month)))+
geom_point()+
geom_smooth(method = "lm",se=FALSE,aes(group=1))+
geom_smooth(method = "lm",se=FALSE)
library(RColorBrewer)
myColors <- c(brewer.pal(5,"Dark2"),"black")
display.brewer.pal(5,"Dark2")
ggplot(airquality,aes(Wind,Temp,col=factor(Month)))+
geom_point()+
geom_smooth(method = "lm",se=FALSE,aes(group=1,col="All"))+
geom_smooth(method = "lm",se=FALSE)+
scale_color_manual("Month",values = myColors)
ggplot(airquality,aes(Wind,Temp,col=factor(Month)))+
geom_point()+
geom_smooth(method = "lm",se=FALSE)+
scale_color_manual("Month",values = myColors)+
facet_grid(.~Month)+
theme_classic()
ggplot(data = mydata, aes(x = year, y = produce))+
scale_x_continuous(breaks=seq(2009,2016,1))+
scale_y_continuous(breaks=seq(300,450,10))+
geom_line()+
geom_point()+
guides(fill = FALSE) + xlab("年份") +
ylab("产量:万吨") + ggtitle("2009~2016年中国药材市场走势图")+theme_bw()+
geom_text(aes(label=produce, y=produce+9,x=year-0.2),
position=position_dodge(0.9),
vjust=0) +
theme(plot.title = element_text(hjust = 0.5))