2017-08-03 83 views
1

因此,我正在爲一些數據創建熱圖,並且讓它顯示按星期幾和小時彙總的車輛數量。但是,當我製作地圖時,傳說似乎不起作用,因此,瓷磚不會達到「最深的紅色陰影」。有誰知道發生了什麼事?謝謝:爲什麼我的ggplot geom_tile傳說比我想要的要高?

Hourplus <- c(Hour, Hour, Hour, Hour, Hour, Hour, Hour, Hour) 
facetgrid <- data.frame(DayofWeek, Totals5, Totals6, Totals3, Totals4, Totals1, Totals2, Totals7, Totals8) 
names(facetgrid) <- c("DayofWeek", "Marine Dr NB", "Marine Dr SB", "Carman NB", "Carman SB", "Glisan NB", "Glisan SB", "Stafford NB", "Stafford SB") 


facetgrid <- melt(facetgrid) 
facetgrid$DayofWeek <- factor(facetgrid$DayofWeek, levels=c("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")) 
facetgrid 
levels(facetgrid$DayofWeek) <- c("M","Tu","W","Th","F","Sa","Su") 
gg <- ggplot(facetgrid, aes(x=Hourplus, y=DayofWeek, fill=value)) + geom_tile(color="white", size=0.1) + facet_wrap(~variable, ncol = 2, scales='free') 
gg <- gg + coord_equal() 
gg <- gg + labs(x=NULL, y=NULL, title ="May 2017: Volume of Vehicles Greater than 20ft in Length") 
gg <- gg + theme_tufte() 
gg <- gg + theme(plot.title=element_text(hjust=0.5)) 
gg <- gg + theme(axis.ticks=element_blank()) 
gg <- gg + theme(axis.text=element_text(size=7)) 
gg <- gg + theme(legend.title=element_text(size=8)) 
gg <- gg + theme(legend.text=element_text(size=6)) 
gg <- gg + scale_fill_gradient(low = "white",high = "red", name="Volume") 
gg <- gg + scale_x_continuous(breaks=seq(0,24,4), limits=c(0,25)) 
ggsave("8stationsvol.png", height =8, width = 12) 

這是地圖是什麼樣子,現在(沒有磚是最黑暗的紅色) Fig

+1

我可以建議從oldish紅色/白色調色板切換到'viridis'嗎? https://cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html從白色背景上的'low ='white''似乎並不是一個好主意。 – PoGibas

+0

感謝您的建議,但我的僱主希望它是這樣的。我現在真的只是想解決這個問題 –

回答

0

Ggplot確實增加了「迴旋」的餘地持續性的最尺度,如與X和Y軸。 要設置嚴格(或自定義)限制,請在scale_fill_gradient內使用「限制」功能。在你的情況下,給它一個下限和上限的向量。

gg + scale_fill_gradient(low = "white", 
     high = "red", 
     name="Volume", 
     limits = c(min(facetgrid$value), max(facetgrid$value))) 
相關問題