我正在尝试制作一个条形图,其中情节从miRNA最高value到miRNA最低排序.为什么我的代码不起作用?
> head(corr.m)
miRNA variable value
1 mmu-miR-532-3p pos 7
2 mmu-miR-1983 pos 75
3 mmu-miR-301a-3p pos 70
4 mmu-miR-96-5p pos 5
5 mmu-miR-139-5p pos 10
6 mmu-miR-5097 pos 47
ggplot(corr.m, aes(x=reorder(miRNA, value), y=value, fill=variable)) +
geom_bar(stat="identity")
Run Code Online (Sandbox Code Playgroud) 我已经在这个论坛中查看了答案,但似乎无法找到这个具体问题的答案.我有以下数据,并希望创建一个条形图,其中条形按"值"从大到小排序,而不是按字母顺序排列:
breadth_data <- read.table(textConnection("Stakeholder Value
'Grantseekers' 0.90
'Donors' 0.89
'Community' 0.55
'Hurricane Relief Fund' 0.24
'Media' 0.19
'Employment Seekers' 0.12
'Affiliates' 0.10
'Youth' 0.09
'Women' 0.02
'Former Board Members' 0.01"), header=TRUE)
Run Code Online (Sandbox Code Playgroud)
然后是基本条形图:
c <- ggplot(breadth_data, aes(x=Stakeholder, y=Value))
c + geom_bar(stat="identity") + coord_flip() + scale_y_continuous('') + scale_x_discrete('')
Run Code Online (Sandbox Code Playgroud)
我已经尝试过在StackOverflow上看到的许多不同的重新排序和转换,但我似乎无法找到一个有效的.我相信这很简单,但我将不胜感激!
谢谢,
格雷格
我有以下 R 代码,我在其中转换数据,然后按特定列对其进行排序:
df2 <- df %>%
group_by(V2, news) %>%
tally() %>%
complete(news, fill = list(n = 0)) %>%
mutate(percentage = n / sum(n) * 100)
df22 <- df2[order(df2$news, -df2$percentage),]
Run Code Online (Sandbox Code Playgroud)
我想在 ggplot 中应用有序数据“df22”:
ggplot(df22, aes(x = V2, y = percentage, fill = factor(news, labels = c("Read","Otherwise")))) +
geom_bar(stat = "identity", position = "fill", width = .7) +
coord_flip() + guides(fill = guide_legend(title = "Online News")) +
scale_fill_grey(start = .1, end = .6) + xlab("Country") + ylab("Share")
Run Code Online (Sandbox Code Playgroud)
不幸的是,ggplot 仍然返回一个没有订单的情节:
有谁知道我的代码有什么问题?这与使用每个条形图的单个值对条形图进行排序不同,例如在 …