non-numeric tick marks in R - r

Newbie Question!
I'm trying to plot a line graph, but the tick-labels on the x-axis have to be non-numeric. How can I do this? So far I have this:
plot(disparitybin$Variance[1,], type="l", xlim=c(0,5.0), ylim=c(0, 0.05), frame=FALSE, xlab="Time", xaxt='n', yaxt='n', ylab="Dispairty (Sum of Variance)", main="Dispairty Through Time", cex.lab=1.25, cex.main=1.75)
axis(1, pos=0, las=0)
axis(2, pos=0, las=2)
I'm trying to specify the names of each tick mark along the x-axis: Eocene, Oligocene, Miocene, Pliocene. How do I get the labels control for the axis() command to accept this info?
Thanks for your help!

Use axis as follows:
axis.labels <- c("Eocene", "Oligocene", "Miocene", "Pliocene")
axis(1, labels=axis.labels, pos=0, las=0)
This assumes that you are plotting exactly four points of data. Also, you were correct to make the call to axis after the call to plot.

Related

How to change the "points" in my graph to become a "bar/histogram bar" in a PRCC plot

I have a question regarding LHS/PRCC in R. I need to change the "points" in my graph to become a "bar/histogram bar" (see the photo). I have solved the LHS/PRCC and plot the values but I require a bar plot of the coefficients. Below is my code.
Below is my code:
plot(summary$original, main='Partial rank correlation coefficients', ylim=c(-1,1),
xlab='', ylab='Coefficient',
axes=FALSE)
axis(2)
axis(1, at=seq(1:8), labels=c("A",expression(lambda[d]),expression(sigma[d]),expression(m[d]),expression(k[d]),expression(mu[d]),'c',expression(beta[d])), las=1)
mtext(text='Parameter', side=1, line=2.5)
box()
#for(i in 1:8) lines(c(i,i),c(summary[i,4], summary[i,5])) #the lines for CI
abline(h=0)

R: Different colours for barplot labels

I have a barplot and would like to have the label showing different colours and the bars to be grey.
I tried:
col_lab <- c("red","green","grey","red","red","blue")
barplot(1:6,names.arg=1:6,main="barplot",las=1,horiz=TRUE,col="grey",xaxt="n",col.names=col_lab)
but I got an error.
Thank you for your help.
Use yaxt="n" and do an mtext. To get the right positions, use the coordinates barplot throws invisibly.
b <- barplot(1:6, names.arg=1:6, main="barplot", las=1, horiz=TRUE, col="grey",
xaxt="n", yaxt="n")
mtext(1:6, 2, .5, at=b, las=2, col=col_lab, font=2)

Removing axes in beeswarm plot

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)

Combining paste() and expression() in plot tick mark labels

Consider this example:
labs <- c("AT~frac(T,C)~G","GGAA","TTAA","AAAA")
plot(c(1:4), c(1:4), axes=F, xlab="",ylab="", par(mar=c(8,3,2,1)))
axis(1, at=c(1:4), labels=labs, las=2)
that generates this:
My intention is to have something like this:
that I hardcoded as:
plot(c(1:4), c(1:4), type="n", axes=F, xlab="",ylab="")
axis(1, at=c(1:4), labels=c(expression(AT~frac(T,C)~G), expression(GGAA), expression(TTAA), expression(AAAA)), las=2)
The closest answer I got was this.
Getting expression() to work as I desired is really very confusing for me. I intend to have these x-axis tick mark labels dynamically generated from available data using a vector of "expression strings".
You were close! frac() is a function that you need to call. it can be used with strings as an argument. This sample
labs <- expression(paste("AT"~frac("T","C")~"G",sep=""),"GGAA","TTAA","AAAA")
plot(c(1:4), c(1:4), axes=F, xlab="",ylab="")
axis(1, at=c(1:4), labels=labs, las=2)
generates this plot:

Unwanted default thick axis lines in R plot function

When I make any plot in R it always results with a thicker axis line along the numbered portion of the surrounding box. It's a nuisance as I must always turn the axes off in plot(), and then redraw them with zero thickness. I've noticed other labmates' computers don't seem to have this problem which makes me wonder where the problem is coming from.
Plot 1 generates my unwanted thick axes lines, Plot 2 works as a solution:
x<-c(1:10)
y<-c(1:10)
# Plot 1
plot(x,y, main="Plot 1")
# Plot 2
plot(x, y, xaxt='n', yaxt='n', main="Plot 2")
axis(1, lwd=0, lwd.ticks=1)
axis(2, lwd=0, lwd.ticks=1)
I'm running RStudio 0.98.501 on Mac OSX 10.9.4
Any ideas on root of the error much appreciated. Thanks.
You could create a new plot function, something along the lines of this should work:
plot = function(x, y, ...){
plot(x, y, xaxt='n', yaxt='n')
axis(1, lwd=0, lwd.ticks=1)
axis(2, lwd=0, lwd.ticks=1)
}

Resources