I have multiple csv files with same structure of data
url, A,B,C,D
a.com,1,2,3,4
b.com,3,4,5,6
I can create a stacked bar plot with urls on x-axis and A,B,C,D stacked on top of each other.
Now I want to create clustered stacked bar plots, with multiple such csv files, all indexed by the same url on the x axis.
data1 = read.csv("data.csv")
data2 = read.csv("data2.csv")
data.m = melt(data1, id.var="url")
ggplot(data.m, aes(x = url, y = value, fill = variable)) +
geom_bar(position="fill",stat = "identity")
Basically add data2 to the plot. Not sure if I am supposed to use gather or facets or manually create new columns post melt?
Is this what you're after?
Using
gather
Using
melt
Sample plot
Note: If you have multiple
csv
files, best todf.list <- lapply(..., read.csv)
, and thenmelt
df.list
to get columnsvariable
,value
andL1
(which corresponds tosrc
).Update
I'm not entirely clear on what you are after, so this is a bit of a stab in the dark. You can also cluster by
url
(instead ofsrc
):and/or show bars side-by-side (instead of stacked)