- 直方圖 Histogram 資料分布狀況
- 散布圖 Scatter plot 兩種變數的關係
- 泡泡圖 Bubble plot 三種變數的關係
ggplot 不能做的事情:
ggplot is a building block of a graph include:
aesthetics + geometric objects
aesthetics 的參數設定:
aes()
geometric objects: geom_()
ggplot(): 準備畫布 (canvas)
讀檔
library(ggplot2)
housing <- read.csv("檔案位置")
head(housing)
# 1.
hist(housing$Home.value)
# 2.
ggplot(housing, aes(x = Home.value)) + geom_histogram()
Learn More →
Learn More →
Traditional plot():
plot(Home.Value ~ Date, data=subset(housing, State == "MA"), type="l")
lines(Home.Value ~ Date, col="red", data=subset(housing, State == "TX"))
legend(1975, 400000, c("MA", "TX"), title="State", col=c("black", "red"), pch=c(1,1))
Learn More →
subset():
對屬性資料表去做查詢並擷取出來
By ggplot():
data <- subset(housing, State %in% c("MA", "TX"))
ggplot(data,aes(x=Date, y=Home.Value, color = State)) + geom_line()
Learn More →
補充 %in% 運算元:
判斷左邊集合的元素有沒有在右邊集合中,有則回傳 TRUE,沒有則回傳 FALSE
hp2001Q1 <- subset(housing, Date == 2001.25)
ggplot(hp2001Q1, aes(y = Structure.Cost, x = Land.Value)) + geom_point()
ggplot(hp2001Q1, aes(y = Structure.Cost, x = log(Land.Value))) + geom_point()
Learn More →
Learn More →
(取LOG)
# 回歸線的截距和係數 (Intercept & coefficient)
model<-lm(Structure.Cost ~ log(Land.Value), data = hp2001Q1)
# 預測值
hp2001Q1$pred.SC <- predict(model)
p1 <- ggplot(hp2001Q1, aes(x = log(Land.Value), y = Structure.Cost))
p1 + geom_point(aes(color = Home.Value)) + geom_line(aes(y = pred.SC))
Learn More →
p1 + geom_point(aes(color = Home.Value)) + geom_smooth()
Learn More →
p1 + geom_point(size = 2, color="red")
Learn More →
p1 + geom_point(aes(color=Home.Value, shape = region))
Learn More →
p1 + geom_point(aes(size=Home.Value, color = region))
Learn More →
ggplot(housing, aes(x=region)) + geom_bar()
Learn More →
ggplot(housing, aes(x=Year, fill=region))
+ geom_bar()
+ labs(title = "Stacked Bar Chart", x = "YEAR", y = "Counts")
Learn More →
housing.sum <- aggregate(housing["Home.Value"], housing["State"], FUN=mean)
ggplot(housing.sum, aes(x=State, y=Home.Value)) + geom_bar(stat='identity') # 一定要指定要畫的資料是什麼stat='identity'
用ggplot2畫圓餅圖的原理是將長條圖的y座標改成極座標
x軸不放資料,用顏色去區分region
housing2.sum <- aggregate(housing["Home.Value"], housing["region"], FUN=length)
ggplot(housing2.sum, aes(x=region, y=Home.Value))+geom_bar(stat='identity')+labs(y="Counts")
ggplot(housing2.sum, aes(x="", y=Home.Value, fill =factor(region)))+geom_bar(stat='identity',width=1)+coord_polar(theta = "y", start=0)
ggplot(housing, aes(x = region, y= Home.Value)) + geom_boxplot(fill = "red")+ scale_y_continuous("hoem value", breaks= seq(0,800000, by=100000))
ggplot(housing, aes(x= Year, y= Qrtr)) + geom_raster(aes(fill = Home.Value)) +scale_fill_continuous(name="Value", breaks = c(200000, 500000, 800000), labels = c("'200", "'500", "'800"), low='gray', high='red')
目標:空間自相關的觀念與計算 全域分析的方法 Point data without attributes Quantrat Analysis 樣方分析 Nearest Neighbor Methods 鄰近分析 Ripley's K-function: K(d) and L(d)
May 8, 2022大綱: 認識GISTools這個library的功能 Mapping spatial objects & data attributes (主題地圖) 1. calculate population density 兩種資料形式: 1. Spatial____dataframe 2. data.frame 設置圖形的函數:par()中的參數介紹 mar=c(btm,left,top,right) 圖形邊界設定
Jun 5, 2021Review: Moran's I 利用統計指標的概念量測是否有空間自相關的存在,並利用假設檢定是否顯著 利用自己與鄰居的共變異數,去了解空間自相關的情況 Moran Correlogram X軸:定義的空間範圍 Y軸:空間自相關的程度(moran's I) Simple Linear Regression Model
Jun 15, 2020熱區分析的空間統計方法 For polygon data: Local moran's I index Local Gi* Local Moran's I 顯著性檢定
Jun 15, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up