我有两个不同的排名方法计算的排名列表。我想绘制这些数据,以便对2个排名列表的相似性进行粗略的定性处理。
我需要显示的数据类似于这些命名的矢量:
rankMathodA = c(1.5, 4, 7, 3, 4.2)
names(rankMathodA) = c("Team1", "Team2", "Team3", "Team4", "Team5")
rankMathodA
#Team1 Team2 Team3 Team4 Team5
# 1.5 4.0 7.0 3.0 4.2
rankMathodB = c(1.7, 3.5, 6.2, 3.9, 4.1)
names(rankMathodB) = c("Team1", "Team2", "Team3", "Team4", "Team5")
rankMathodB
#Team1 Team2 Team3 Team4 Team5
# 1.7 3.5 6.2 3.9 4.1
答案 0 :(得分:3)
这是一个ggplot方法的开始,有一些重塑数据。标签(使用geom_text
分别添加以控制文字展示位置。
library(reshape2)
library(ggplot2)
#create a dataframe with all necessary variables
dat <- data.frame(team=c("Team1", "Team2", "Team3", "Team4", "Team5"),
rankA=c(1.5, 4, 7, 3, 4.2),
rankB=c(1.7, 3.5, 6.2, 3.9, 4.1))
#turn to long
dat_m <- melt(dat,id.var="team")
#plot
ggplot(dat_m, aes(x=variable, y=value, group=team)) +
geom_line() +
geom_text(data=dat_m[dat_m$variable=="rankA",],aes(label=team),hjust=1.1) +
geom_text(data=dat_m[dat_m$variable=="rankB",],aes(label=team),hjust=-0.1) +
geom_vline(xintercept = c(1,2)) +
#hide axis, labels, grids.
theme_classic() +
theme(
axis.title = element_blank(),
axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank())