I have 3 datasets df1, df2, df3, each containing three columns (csv files: https://www.dropbox.com/s/56qh1l5kchsiof0/datasets.zip?dl=0)
Each dataset represents a staked bar graph of the three columns, like so:
This example shows df3, where the three columns of the dataset df3.csv are stacked one on top of the other
Here's my r code to produce the above plot:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
df = read.csv(".../df3.csv",sep=",", header=TRUE)
df.m = melt(df,c("density"))
c = ggplot(df.m, aes(x = density, y = value/1e+06,fill = variable)) + labs(x = "Density", y = "Cumulated ranks",fill = NULL)
c = c + geom_bar(stat = "identity", position = "stack") + scale_fill_grey(..., start = 0.2, end = 0.8, na.value = "grey50")
c = c + ggtitle('Relative valuation of 75-node resilient networks\naccording to their density') + theme(plot.title = element_text(lineheight=.8, face="bold"))
c
I now need to build a facet plot where df1, df2, and df3 (each showing the three columns, staked) would share the same x axis scale, as such:
I'm sorry for the terrible doodle... Also, each subplot should be a stacked bar graph, as on figure 1, not a density plot
Can I just do something like this:
require(reshape2)
library(ggplot2)
library(RColorBrewer)
df = read.csv(".../df1.csv",sep=",", header=TRUE)
df.m = melt(df,c("density"))
a = ggplot(df.m, aes(x = density, y = value/1e+06,fill = variable)) + labs(x = "Density", y = "Cumulated ranks",fill = NULL)
a = a + geom_bar(stat = "identity", position = "stack") + scale_fill_grey(..., start = 0.2, end = 0.8, na.value = "grey50")
a = a + ggtitle('subtitle 1') + theme(plot.title = element_text(lineheight=.8, face="bold"))
df = read.csv(".../df2.csv",sep=",", header=TRUE)
df.m = melt(df,c("density"))
b = ggplot(df.m, aes(x = density, y = value/1e+06,fill = variable)) + labs(x = "Density", y = "Cumulated ranks",fill = NULL)
b = b + geom_bar(stat = "identity", position = "stack") + scale_fill_grey(..., start = 0.2, end = 0.8, na.value = "grey50")
b = b + ggtitle('subtitle 2') + theme(plot.title = element_text(lineheight=.8, face="bold"))
df = read.csv(".../df3.csv",sep=",", header=TRUE)
df.m = melt(df,c("density"))
c = ggplot(df.m, aes(x = density, y = value/1e+06,fill = variable)) + labs(x = "Density", y = "Cumulated ranks",fill = NULL)
c = c + geom_bar(stat = "identity", position = "stack") + scale_fill_grey(..., start = 0.2, end = 0.8, na.value = "grey50")
c = c + ggtitle('subtitle 3') + theme(plot.title = element_text(lineheight=.8, face="bold"))
all = facet_grid( _???_ )
Or need I organize my data differently?