[問題] lattice繪圖問題

看板R_Language作者 (暗夜流光)時間6年前 (2019/05/13 15:49), 6年前編輯推噓1(104)
留言5則, 2人參與, 6年前最新討論串1/1
各位板友大家好,首次發文,是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軸的順序,讓它符合我預想的圖像,但是怎麼調整都失敗,所以想請教各位 這個要如何修改,非常感謝大家! -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.88.42 ※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1557733796.A.C2D.html

05/13 16:16, 6年前 , 1F
dotplot() 裡的 Type 改成
05/13 16:16, 1F

05/13 16:17, 6年前 , 2F
factor(Type, levels = c("Populist", "Mixed", "Nonpop
05/13 16:17, 2F

05/13 16:17, 6年前 , 3F
ulist"))
05/13 16:17, 3F

05/13 16:20, 6年前 , 4F
這招在類別型座標軸很常用
05/13 16:20, 4F
順利的跑出來了 感謝您的協助! ※ 編輯: rickydai888 (111.250.88.42), 05/13/2019 16:37:28

05/15 13:52, 6年前 , 5F
SigmaPlot其實也不錯用xd
05/15 13:52, 5F
文章代碼(AID): #1SsI6amj (R_Language)
文章代碼(AID): #1SsI6amj (R_Language)