我有以下数据:
输入Rtime Rcost Rsolutions Btime Bcost 1 12 proc。 1 36 614425 40 36 2 15 proc。 1 51 534037 50 51 3 18-proc 5 62 1843820 66 66 4 20-proc 4 68 1645581 104400 73 5 20-proc(l)4 64 1658509 14400 65 6 21-proc 10 78 3923623 453600 82我想根据这些数据创建一个分组条形图这样x轴包含 Input 字段(作为组),y轴代表Rtime和Btime字段(两个条)的日志比例。
我在网上查过的所有解决方案/示例都将相似的数据放入三列布局中。我不知道如何使用我必须生成分组条形图的数据。或者,如果有方法将这些数据转换为 R 和 ggplot 兼容数据(手动转换不是选项,因为它是一个包含大量行的大文件)格式。
编辑: 使用gncs解决方案生成的图表
<根据要求,一个 ggplot2 解决方案: <$ c $ c> df < - read.table(text =Input Rtime Rcost Rsolutions Btime Bcost 1 12-proc。1 36 614425 40 36 2 15-proc。1 51 534037 50 51 3 18-proc 5 62 1843820 66 66 4 20-proc 4 68 1645581 104400 73 5 20-proc(l)4 64 1658509 14400 65 6 21-proc 10 78 3923623 453600 82,header = TRUE,sep =) dfm < - melt(df [,c('I (b)')],id.vars = 1) ggplot(dfm,aes(x = Input,y = value))+ geom_bar(aes (fill = variable),stat =identity,position =dodge)+ scale_y_log10()
请注意风格的不同之处,自 log(1)= 0 , ggplot2 将其视为零高度的柱状图,不会绘制任何东西,而 barplot 绘制了一个小存根(在我看来这有点误导)。
I have the following data
Input Rtime Rcost Rsolutions Btime Bcost 1 12 proc. 1 36 614425 40 36 2 15 proc. 1 51 534037 50 51 3 18-proc 5 62 1843820 66 66 4 20-proc 4 68 1645581 104400 73 5 20-proc(l) 4 64 1658509 14400 65 6 21-proc 10 78 3923623 453600 82I want to create a grouped bar chart from this data such that x-axis contains Input field (as groups) and y axis represent the log scale for the Rtime and Btime fields (the two bars).
All solutions/examples I checked online had similar data put into a three column layout. I do not know how to use the data I have to generate the grouped bar-chart. Or if there is a way to convert this data (manually converting is not an options because it is a huge file with a lot of rows) into a R and ggplot compatible data format.
Edit :
Graph generated using gncs solution
解决方案As requested, a ggplot2 solution:
df <- read.table(text = " Input Rtime Rcost Rsolutions Btime Bcost 1 12-proc. 1 36 614425 40 36 2 15-proc. 1 51 534037 50 51 3 18-proc 5 62 1843820 66 66 4 20-proc 4 68 1645581 104400 73 5 20-proc(l) 4 64 1658509 14400 65 6 21-proc 10 78 3923623 453600 82",header = TRUE,sep = "") dfm <- melt(df[,c('Input','Rtime','Btime')],id.vars = 1) ggplot(dfm,aes(x = Input,y = value)) + geom_bar(aes(fill = variable),stat = "identity",position = "dodge") + scale_y_log10()Note a style difference here, where since log(1) = 0, ggplot2 treats that as a bar of zero height and doesn't plot anything, whereas barplot plots a little stub (which in my opinion is a little misleading).
更多推荐
在R中创建多列数据的分组条形图
发布评论