我试图制作一个条形图,其中最大的条最接近y轴,最短的条最远.所以这有点像我的表
Name Position
1 James Goalkeeper
2 Frank Goalkeeper
3 Jean Defense
4 Steve Defense
5 John Defense
6 Tim Striker
Run Code Online (Sandbox Code Playgroud)
所以我正在尝试建立一个条形图,根据位置显示玩家数量
p <- ggplot(theTable, aes(x = Position)) + geom_bar(binwidth = 1)
Run Code Online (Sandbox Code Playgroud)
但是图表显示守门员杆然后是防守,最后是前锋一个.我希望图表被排序,以便防守栏最接近y轴,守门员一个,最后是前锋一个.谢谢
我想创建一个分组条形图,其中的组以特定顺序出现。这里有一个详细的例子。
df <- data.frame(Groups = c("B","B","B","C","C","A","A","A","A","A"),
Ages = c(3,4,4,5,3,4,5,3,3,5))
df_cast <- dcast(data = df, formula = Groups ~ Ages)
df_bars <- melt(data = df_cast, id.vars = 'Groups')
ggplot(data = df_bars, aes( x = Groups, y = value, fill = variable ) ) +
geom_bar( stat = 'identity', position = 'dodge' ) +
labs(title="Groups ages", x = "Groups", y = "Frecuency") +
labs(fill = "Ages") + theme(plot.title = element_text(hjust = 0.5))
Run Code Online (Sandbox Code Playgroud)
组是 B、C 和 A,我希望它们按顺序出现在条形图中,上面的命令按字母顺序排列它们。