2014-08-29 132 views
-1

我有一個名爲city的列,它有10多個不同的城市,並且這些值分散在10000行之外。現在我想根據10個城市中的特定城市進行一些探索性分析。 我寫currently-使用R中特定列的幾個值進行繪圖ggplot

ggplot(irdata,aes(x=City))+geom_histogram(binwidth=5) 

ggplot(irdata, aes(x = City,y=50, fill = Section)) +geom_bar(stat = "identity", position = "dodge") + coord_flip() 

在這兩個我使用所有這一切,我不希望城市繪製的。如何繪製使用一些特定的城市像

ggplot(irdata,aes(x=City=='Dublin'))+geom_histogram(binwidth=5) 

但上面這段代碼無論如何也不會工作,因爲它會帶來與邏輯輸出/結果。

回答

2

嘗試:

ggplot(irdata[irdata$City=='Dublin',],aes(x=City))+geom_histogram(binwidth=5) 
+0

如果我有超過1個城市測試像都柏林,科克,倫敦..這樣 – 2014-08-29 14:19:34

+1

使用irdata [irdata $%%c(「都柏林」,「科克」,「倫敦」),] – rnso 2014-08-29 16:06:16

1

大約只子集劃分的數據是什麼?

ggplot(subset(irdata, City == "Dublin"),aes(x=City))+geom_histogram(binwidth=5) 
+0

如果我有超過1個城市測試像都柏林,科克,倫敦......就這樣 – 2014-08-29 14:21:40

0

這應該是一個評論,因爲它基本上是一樣的其他答案(除「在%城市%..),但我不能刪除它:-(

ggplot(子集(irdata,城市%在%c(「都柏林」,「科克」,「倫敦」)),aes(x =城市))+ geom_histogram(binwidth = 5)