i plot 3 plots in same window. each have different amount of bar plots. how make them same size , close (same distance each other) without doing nas in smaller barplots. example code below. want point out real data plotting numbers dataframes$columns not vector of numbers shown below. sure there magic way cant seem find helpful info on net. thanks
pdf(file="path".pdf"); par(mfrow=c(1,3)); par(mar=c(9,6,4,2)+0.1); barcenter1<- barplot(c(1,2,3,4,5)); mtext("average emergent", side=2, line=4); par(mar=c(9,2,4,2)+0.1); barcenter2<- barplot(c(1,2,3)); par(mar=c(9,2,4,2)+0.1); barcenter3<- barplot(c(1,2,3,4,5,6,7)); or there way instead of using par(mfrow....) make plot window, group barcenter data on single plot empty space between bars? way spaced , looks same?
using parameters xlim , width:
par(mfrow = c(1, 3)) par(mar = c(9, 6, 4, 2) + 0.1) barcenter1 <- barplot(c(1, 2, 3, 4, 5), xlim = c(0, 1), width = 0.1) mtext("average emergent", side = 2, line = 4) par(mar = c(9, 2, 4, 2) + 0.1) barcenter2 <- barplot(c(1, 2, 3), xlim = c(0, 1), width = 0.1) par(mar = c(9, 2, 4, 2) + 0.1) barcenter1 <- barplot(c(1, 2, 3, 4, 5, 6, 7), xlim = c(0, 1), width = 0.1) 
introducing zeroes:
df <- data.frame(barcenter1 = c(1, 2, 3, 4, 5, 0, 0), barcenter2 = c(1, 2, 3, 0, 0, 0, 0), barcenter3 = c(1, 2, 3, 4, 5, 6, 7)) barplot(as.matrix(df), beside = true) 
with ggplot2 can this:
df <- data.frame(x=c(1, 2, 3, 4, 5,1, 2, 3,1, 2, 3, 4, 5, 6, 7), y=c(rep("bar1",5), rep("bar2",3),rep("bar3",7))) library(ggplot2) ggplot(data=df, aes(x = x, y = x)) + geom_bar(stat = "identity")+ facet_grid(~ y) 
for option mentioned in second comment need:
x <- c(1, 2, 3, 4, 5, na, 1, 2, 3, na, 1, 2, 3, 4, 5, 6, 7) barplot(x) 
Comments
Post a Comment