ggplot(trade,aes(x='',y=value,fill=factor(countries)))
geom_bar(width=1,stat='identity')
coord_polar(theta = 'y',start=0)
labs(title = 'Dairy products imported',y='Dollar amount in 1000\'s' )
我不希望世界部分顯示在我的餅圖上,但是我不想將它從我的資料框中完全洗掉,因為它與我的其他圖表相關。

樣本資料
1 World 2010 463000
2 France 2010 145000
3 New Zealand 2010 191000
4 United States of America 2010 126000
5 Denmark 2010 0
6 Ireland 2010 0
7 Trinidad and Tobago 2010 0
8 World 2011 525000
9 France 2011 266000
10 New Zealand 2011 122000
uj5u.com熱心網友回復:
您需要filter()找出國家是世界的觀察結果。使用 dplyr,將其通過管道傳輸到您的 ggplot 呼叫中。
trade %>%
filter(countries != "World") %>%
ggplot(aes(x='',y=value,fill=factor(countries)))
geom_bar(width=1,stat='identity')
coord_polar(theta = 'y',start=0)
labs(title = 'Dairy products imported',y='Dollar amount in 1000\'s' )
一個基本的 R 版本是
ggplot(trade[trade$countries!="World",], aes(x='',y=value,fill=factor(countries)))
geom_bar(width=1,stat='identity')
coord_polar(theta = 'y',start=0)
labs(title = 'Dairy products imported',y='Dollar amount in 1000\'s' )
您只是使用邏輯運算過濾/子集資料,其中!=均值不等于。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/384668.html
下一篇:按年份過濾繪制點
