[问题] lattice绘图问题

楼主: rickydai888 (暗夜流光)   2019-05-13 15:49:54
各位板友大家好,首次发文,是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:00
dotplot() 里的 Type 改成factor(Type, levels = c("Populist", "Mixed", "Nonpopulist"))这招在类别型座标轴很常用
作者: rocusauk520 (Melo)   2019-05-15 13:52:00
SigmaPlot其实也不错用xd

Links booklink

Contact Us: admin [ a t ] ucptt.com