各位板友大家好,首次發文,是R的新手,想請教以下問題,另外手機排版傷眼抱歉!
我要把以下資料:
library(dplyr)
DT <- tibble(Country=c("Spain", "France", "Germany","Italy", "Sweden"),Popul
ist=c(52,58,65,50, 73),Mixed=c(70,72,70,65,81),Nonpopulist=c(85,84,88,68, 90
))
繪製成點狀圖,而我的語法如下:
DT_tidy<-gather(data = DT,key = "Type", value = "Percentage",Populist, Mixed
,Nonpopulist)
library(lattice)
DT_tidy2<-as.data.frame(DT_tidy)
NDT_tidy2<-dotplot( Percentage~Type ,DT_tidy2, group=Country,type = "o")
update(NDT_tidy2, auto.key=list(points=T, lines=T))
本來按照範例的圖片,應該會長這個樣子:
https://i.imgur.com/xQBDUQm.jpg
而我自己預期繪圖結果應長這樣:
https://i.imgur.com/hfIK4K8.jpg
但是結果跑出來變成這樣:
https://i.imgur.com/7mRGN2P.jpg
我想要調整X軸的順序,讓它符合我預想的圖像,但是怎麼調整都失敗,所以想請教各位
這個要如何修改,非常感謝大家!
作者:
andrew43 (討厭有好心推文後刪文者)
2019-05-13 16:16:00dotplot() 裡的 Type 改成factor(Type, levels = c("Populist", "Mixed", "Nonpopulist"))這招在類別型座標軸很常用