[R] Stacked bar plot of frequency vs time

marcel marcelcurlin at gmail.com
Fri Jul 15 09:10:44 CEST 2011


Thank you for the solutions! 

I have the first one working and it does exactly what I am looking for.
Unfortunately I have to put the plot in a common figure alongside other
plots made in the basic environment (challenging!). With the second method,
I was unable to make the stacked bars locate to the appropriate positions
along the X axis (ie the appropriate time), which, though unconventional is
required for my figure. So I am still looking for a complete solution in the
basic plotting environment. 

I have boiled my problem down to this minimal example: 

# Made-up 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
attach(data1)
par(mar=c(1,1,1,1))
plot(Time, 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=" ")
detach(data1)

# PLOT2 barplot
require(lattice)
attach(data2)
barchart(values ~ Time, group=ind, data=data2, stack=TRUE, horizontal=FALSE,
main="not there yet")
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 can I plot below plot1?")
print(plot2)
detach(data2)

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 for all of your
thoughts.

Marcel

Marcel

--
View this message in context: http://r.789695.n4.nabble.com/Stacked-bar-plot-of-frequency-vs-time-tp3659715p3669311.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list