When creating a plot using gplots.plotmeans, the axis labels are not set to what I want, but to "means" and "Index".
Here is the code:
library(gplots)
plotmeans(ioe.dimension ~ ioe$profile,
col=3,
xlab="Profile", ylab="Means",
ylim=c(2.5,6.5),
bars=FALSE)
abline(h=4, lty=2, col=2)
The resulting plot is this:
This happens for some reason when bars = FALSE. I don't know why, but for me it works to first remove the labels with ann = F and then add them with a call to title().
library(gplots)
plotmeans(ioe.dimension ~ ioe$profile,
col=3,
ylim=c(2.5,6.5),
bars=FALSE,
ann=F)
title(xlab="Profile", ylab="Means")
abline(h=4, lty=2, col=2)
Related
I am trying to plot two different graph in one plot. But, the labeling in y axis is overlapping even though is the labeling is same. Here is my data-
data file 1
data file 2
I used the following code-
plot(`2000_svm_movie`,type="o",col="blue",xlab="Training Years",ylab="Performances", axes=FALSE)
axis(1,at=seq(2000,2014,by=1),las=2)
axis(2,at=seq(78,82,by=1),las=1)
par(new = TRUE)
plot(`2000_random_movie`,type="o",col="red",xlab="Training Years",ylab="Performances", axes=FALSE)
axis(1,at=seq(2000,2014,by=1),las=2)
axis(2,at=seq(78,86,by=1),las=1)
I want Y axis will be labeled like (78,79,80,81,82,83,84,85,86). How can I do this?
You have to add your data, but so far I understand you want something like this?
plot(NULL, xlim=c(2007, 2014), ylim=c(78,86), xlab="Training Years", ylab="Performances")
axis(side=2, at=c(78:86), labels=c(78:86))
x1 <- c(2007:2014)
y1 <- runif(8,78,86)
lines(x1, y1, col="blue")
points(x1,y1, col="blue")
y2 <- runif(8,78,86)
lines(x1, y2, col="red")
points(x1,y2, col="red")
I have a following "beeswarm" (a single-dimensional scatterplot)
library(beeswarm)
data(breast)
beeswarm(breast$time_survival,horizontal=TRUE)
Here is the resulting plot:
How can I get rid of the axes and the box around the plot, so that I can reintroduce only the X axis and nothing else around it?
If you create an empty plot first
plot(rnorm(10), type="n", axes=FALSE, xlim=c(0, 200), ylim=c(0.4, 1.6),
xlab="", ylab="")
Then you can use the add argument to get what you want
beeswarm(breast$time_survival,horizontal=TRUE, add=TRUE)
You can use the "axes" argument (described in ?plot.default).
beeswarm(breast$time_survival, horizontal=TRUE, axes = FALSE)
I'm plotting multiple data series.
colos=c('red','green','purple','pink','brown')
par(new=F)
for (i in 1:5)
{
plot(dat[[i+1]],col=colos[i],cex=marksize,xlab='Reading #',ylab = 'Current')
par(new=T)
}
My plot looks like this:
Is there a way I can overwrite the plot axis with each iteration, but not overwrite the plotted points?
You may want to use the lines or points function(s) instead. Here's an example of how I usually go about this problem. This way you only overlay points on top of the existing plot, instead of plotting one plot on top of another.
Plot the first one with your original plot call, then use lapply to overlay the other columns' points on top of that.
set.seed(1)
dat <- data.frame(replicate(5, sample(10)))
colos <- c('red','green','purple','pink','brown')
plot(dat[[1]], col = colos[1], xlab = 'Reading #',
ylab = 'Current', ylim = range(as.matrix(dat)))
invisible(lapply(2:ncol(dat), function(i) points(dat[[i]], col = colos[i])))
Turn off the axes using xaxt and yaxt
E.g.:
plot(1:10)
par(new=TRUE)
plot(1:10, rnorm(10), xaxt="n", yaxt="n", xlab="", ylab="", type="l")
axis(side=4)
I want to make a histogram for multiple variables.
I used the following code :
set.seed(2)
dataOne <- runif(10)
dataTwo <- runif(10)
dataThree <- runif(10)
one <- hist(dataOne, plot=FALSE)
two <- hist(dataTwo, plot=FALSE)
three <- hist(dataThree, plot=FALSE)
plot(one, xlab="Beta Values", ylab="Frequency",
labels=TRUE, col="blue", xlim=c(0,1))
plot(two, col='green', add=TRUE)
plot(three, col='red', add=TRUE)
But the problem is that they cover each other, as shown below.
I just want them to be added to each other (showing the bars over each other) i.e. not overlapping/ not covering each other.
How can I do this ?
Try replacing your last three lines by:
plot(One, xlab = "Beta Values", ylab = "Frequency", col = "blue")
points(Two, col = 'green')
points(Three, col = 'red')
The first time you need to call plot. But the next time you call plot it will start a new plot which means you lose the first data. Instead you want to add more data to it either with scatter chart using points, or with a line chart using lines.
It's not quite clear what you are looking for here.
One approach is to place the plots in separate plotting spaces:
par("mfcol"=c(3, 1))
hist(dataOne, col="blue")
hist(dataTwo, col="green")
hist(dataThree, col="red")
par("mfcol"=c(1, 1))
Is this what you're after?
I would like to create a very simple plot.
I am using this data:
a <- read.table("https://dl.dropbox.com/u/22681355/a.csv", sep=',', header=TRUE)
plot(a$X25, type="l",col="red", ylim=c(0,100))
lines(a$X25.1, type="l", col="blue")
lines(a$X25.2, type="l", col="green")
lines(a$X25.3, type="l", col="brown")
Now I would like to add a simple legend that indicates which color is which variable.
I understand that I can use the legend() command, but my problem is that I don't know how to put colors next to the text in the legend.
What's the simplest command that would do this?
Take a look at ?legend and try this:
legend('topright', names(a)[-1] ,
lty=1, col=c('red', 'blue', 'green',' brown'), bty='n', cex=.75)