您好我有一个熔融数据集,其中包含分类变量的不同组的中位数排名。因为它是排名,我想实际想出一个图表,在y轴的顶端绘制1s和2s,以表明他们是高排名,而不是低排名。目前,我创建的图表在y轴的低端显示了1s和2s的信息,当然,如果你正在绘制一个传统的连续变量,其中更高的值更高,那么这是有意义的。我尝试过逆转这些值,但这对于facets命令来说确实很奇怪。
感谢您的任何建议。
#Load libraries
library(ggplot2)
#My data
test<- structure(list(d3 = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("Professional
journalist",
"Elected politician", "Online blogger"), class = "factor"), variable =
structure(c(2L, 2L, 2L, 1L, 1L, 1L, 5L, 5L, 5L, 3L, 3L, 3L, 4L, 4L, 4L, 7L,
7L, 7L, 6L, 6L, 6L), .Label = c("Information", "Accessible", "Debate",
"Officials", "Responsive", "Trade-Offs", "Social"), class = "factor"),
value = c(2, 3, 4, 1, 2.5, 2, 4, 3, 3, 4, 3, 3, 3, 4, 4, 7, 6, 7, 5, 4,
4)), row.names = c(NA, -21L), .Names = c("d3", "variable", "value"), class =
"data.frame")
#Plot
ggplot(test, aes(x=d3, y=value, group=d3))+geom_bar(stat='identity',
aes(fill=d3))+facet_wrap(~variable)
#Try reversing the values of value
test$value2<-rev(test$value)
#Replotting
ggplot(test, aes(x=d3, y=value2, group=d3))+geom_bar(stat='identity',
aes(fill=d3))+facet_wrap(~variable)
这种重新绘制似乎只是改变了方面:&#34;信息&#34;现在正在显示&#34; social&#34;的前值,但是在&#34;信息&#34;
的标题下答案 0 :(得分:0)
这是您的想法,设置不同的价值水平吗?
test$value <- factor(test$value, levels = c("7", "6", "5", "4", "3", "2", "1"))
ggplot(test, aes(x=d3, y=value, group=d3)) + geom_bar(stat ='identity', aes(fill=d3)) + facet_wrap(~variable)]