2017-04-11 104 views

回答

0

創建ggplot一個數據幀,然後條形圖,使用ggplot標籤:

# my example uses some raster data 
require(ggplot2) 
require(raster) 
r <- raster("myraster.tif") 
f <- hist(r, breaks=10) 
dat <- data.frame(counts= f$counts,breaks = f$mids) 

ggplot(dat, aes(x = breaks, y = counts, fill =counts)) + 
    geom_bar(stat = "identity")+ 
    scale_x_continuous(breaks = f$mids,labels = c("0 to 0.1","0.1 to 0.2","0.2 to 0.3","0.3 to 0.4","etc","etc","etc","etc","etc","etc")) 
+0

我必須使用光柵功能? – Bonsaibubble

+0

我不太明白你爲什麼要創建「r」和「f」?代碼似乎不適合我。 – Bonsaibubble

+0

@Bonsaibubble你給了很少的工作:你有什麼樣的數據,你想要做什麼(做一個直方圖我猜),這些'名字'出現在哪裏(X軸?)。我剛剛提出了一個想到的例子。不,這個例子純粹是爲了光柵。 – Sam