Ram H. Sharma
2011-May-15 15:17 UTC
[R] pls help: lattice graph with both negative and positive value, x and y cross at 0 and negative value bars are plotted just oppositive direction in contrast to positive
Dear R experts: Here is my problem: #Data 1 Y <- c(0.5, 0.1, 0.5, 1.3, 1.4, 1.6, 1.65, 2.4, 2.6, 3.4, 3.6, 4.3, 4.42, 4.8, 4.7, 3.4, 3.3, 2.8, 2.8, 1.2, 1.1, 0.5, 0.2, 0.1, -0.2, -1.5, -2.5, -1.3, -0.5, -0.1) X <- seq(1:30) X1 <- c(rep("T1", 24), rep("T2", 6)) dat1 <- data.frame(Y, X, X1) require(lattice) mcol <- c("green", "red") barchart(Y ~ factor (X), group = X1, data = dat1, col = mcol , ylab= "y var", xlab = "x var", ylim = c(-3.0, 5.0), pos = 0, scales list(x=list(rot= 90, font = 1, cex = 1) , y = list(rot= 90, font = 1, cex 1) )) The output is not what I want. I want the orientation of graph like the following in base R but axis label are in Y axis line and other parameters as in lattice: barplot(Y, names.arg = X) I know this is simple question, but I could not find a true solution. -- Thanks in advance. Ram H [[alternative HTML version deleted]]
Dennis Murphy
2011-May-15 21:03 UTC
[R] pls help: lattice graph with both negative and positive value, x and y cross at 0 and negative value bars are plotted just oppositive direction in contrast to positive
Hi: Try this: barchart(Y ~ factor(X), group = X1, data = dat1, col = mcol, origin = 0, ylab= "y var", xlab = "x var", ylim = c(-3.0, 5.0), scales = list(x=list(rot= 90, font = 1, cex = 1) , y = list(rot= 90, font = 1, cex = 1) )) The origin = argument comes from panel.barchart(); see its help page for more details. HTH, Dennis On Sun, May 15, 2011 at 8:17 AM, Ram H. Sharma <sharma.ram.h at gmail.com> wrote:> Dear R experts: > > Here is my problem: > > > #Data 1 > > Y <- c(0.5, 0.1, 0.5, 1.3, 1.4, 1.6, 1.65, 2.4, 2.6, 3.4, 3.6, 4.3, 4.42, > 4.8, 4.7, 3.4, 3.3, 2.8, 2.8, 1.2, 1.1, 0.5, 0.2, 0.1, -0.2, -1.5, -2.5, > -1.3, -0.5, -0.1) > > X <- seq(1:30) > > X1 <- c(rep("T1", 24), rep("T2", 6)) > > dat1 <- data.frame(Y, X, X1) > > > > require(lattice) > > mcol <- c("green", "red") > > barchart(Y ~ factor (X), group = X1, data = dat1, ?col = mcol , ylab= "y > var", xlab = "x var", ylim = c(-3.0, 5.0), pos = 0, ?scales > list(x=list(rot= 90, font = 1, cex = 1) , y = list(rot= 90, font = 1, cex > 1) )) > > The output is not what I want. I want the orientation of graph like the > following in base R but axis label are in Y axis line and other parameters > as in lattice: > > barplot(Y, names.arg = X) > > I know this is simple question, but I could not find a true solution. > > -- > Thanks in advance. > > Ram H > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >