I am creating a multi-plot figure with a scatter plot at the top of the page and a bar chart on the lower part. The bar chart shows the frequecies of Types 1, 2 and 3 at various times. Each bar is of height = 1, subsections of bars proportional to the frequency, and each bar located at the correct (time) position on a continuous X-axis.
I can make each plot work individually, but the only solution I found for the bar plot involves lattice plots, and I can't figure out how to put both the basic plot and the (lattice) bar plot on the same page. I have boiled my problem down to this minimal example:
The only thing left is to get both plots to be vertically aligned, one above the other on the same figure. Is this possible? Thanks,
Marcel
I can make each plot work individually, but the only solution I found for the bar plot involves lattice plots, and I can't figure out how to put both the basic plot and the (lattice) bar plot on the same page. I have boiled my problem down to this minimal example:
Code:
# Example data
tC <- textConnection("
Time Type1 Type2 Type3
1.3 .50 .25 .25
4.5 .55 .25 .20
5.2 .65 .20 .15
")
data1 <- read.table(header=TRUE, tC)
data2 <- data.frame(Time=rep(data1$Time, 3), stack(data1[,2:4]))
close.connection(tC)
#PLOT1 Scatterplot
par(mfrow=c(2,1))
plot(data1$Time, data1$Type1, frame=T, ylab="Divergence", col=rgb(0,100,0,50,maxColorValue=255), main="plot 1", xlim= c(0,6), ylim= c(0, 1), axes=FALSE, xlab=" ")
#PLOT2 barplot
require(lattice)
plot2 <- xyplot(values ~ Time, group=ind, data=data2, stack=TRUE, horizontal=FALSE, panel=panel.barchart, ylim=c(-0.05,1.05), xlim=c(0,6), main="Plot 2- how to plot on same page below plot1?")
print(plot2)
Marcel
Last edited by a moderator: