Here is some R code and the graph it produces:
这里是一些R代码和它产生的图形:
library(ggplot2)
year <- c("1950", "1950", "1960", "1960", "1970", "1970")
weight <- c(15, 10, 20, 25, 18, 20)
name <- c("obj1", "obj2", "obj3", "obj4", "obj5", "obj1")
object.data <- data.frame(year, weight, name)
ggplot(object.data, aes(x=factor(year), y=weight,
fill=reorder(name, -weight))) + geom_bar(stat="identity", position="dodge")
How do I ensure that the bars are sorted from highest to lowest (by weight
) within each individual group?
如何确保每个组中的条形从最高到最低(按权重)排序?
Note that obj1
appears twice, under two different dates, with two different weight
values.
注意,obj1在两个不同的日期出现两次,有两个不同的权重值。