好困了,直接放補(bǔ)充練習(xí)答案,有人問(wèn)再說(shuō)唄
rm(list = ls())
library(ggplot2)
#theme_set(theme_bw(base_size = 14))#設(shè)置主題為白色(個(gè)人愛好)
#創(chuàng)建一個(gè)airquality的wind的直方圖
qplot(x = Wind,data = airquality,binwidth = 2,color = I("red"))
#為每一個(gè)month創(chuàng)建一個(gè)wind的箱線圖
airquality$Month <- factor(airquality$Month)#要弄成因子,變成分類變量
qplot(x = Month,y = Wind,data = airquality, geom = "boxplot")
#Wind和Ozone的關(guān)系,加標(biāo)題,軸標(biāo)簽,讓X軸從0開始,加一條直線
qplot(data = airquality,x = Wind,y = Ozone,
main = "Ozone & Wind",
xlab = "Wind (mph)",
ylab = "Ozone (ppb)",
xlim = c(0,25)) +
geom_smooth(method = lm,formula = y ~ x,se = F)
#使用demoData數(shù)據(jù)畫Weight和Height 散點(diǎn)圖用不同男女區(qū)分顏色,根據(jù)是否抽煙
#用不同符號(hào)
library(mangoTraining)
demoData <- mangoTraining::demoData
head(demoData)
qplot(data = demoData,x = Weight,y = Height ,color = Sex,shape = Smokes,size = 10)
#創(chuàng)建分面繪圖,行是性別,列是吸煙與否
qplot(data = demoData,x = Weight,y = Height,facets =Sex ~ Smokes)
#繪制美國(guó)地圖,每個(gè)州用不同的顏色表示,圖例放在底部,將州化為10行
install.packages("maps")
install.packages("mapproj")
library(maps)
library(mapproj)
library(ggplot2)
state <- map_data("state")
head(state)
state$region <- factor(state$region)
par(mar=c(1,1,1,1))
p <- ggplot(state,aes(x = long,y = lat,group = region,col = region,fill = region))+
geom_polygon(colour="black") +
guides(fill = guide_legend(title = "state",
ncol = 10,
title.position = "top",
label.position = "top",
label.hjust = 0.5,
label.vjust = 1,
label.theme = ))+
theme(legend.position = "bottom")
dev.off()
#轉(zhuǎn)換該圖,使用墨卡托投影
p + coord_map("mercator")
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。