Adding more detailed tick marks to x axes in density plot in R

2.3k views Asked by At

This problem was solved using this coding.

Using the package lattice:

xticks=c(0.0, 0.043, 0.052, 0.173, 0.178, 0.200, 0.360, 0.0, 0.1, 0.2, 0.3, 0.4, 0.5)

yticks=c(0, 5, 10, 15)

densityplot(~Wart,group=Species, data=datum, xlab="Wart to spot ratio", ylab="Frequency", scales=list(x=list(at=xticks), y=list(at=yticks)))

1

There are 1 answers

1
Ilari Scheinin On

Unless you have some reason why you need lattice, you can make density plots also with the base graphics, and then axis() will work:

x <- rnorm(1000)
plot(density(x))
axis(side=1, at=c(-1, 1))

Update:

Here's with three distributions:

x <- rnorm(1000)
y <- rnorm(1000, -1)
z <- rnorm(1000, 1)

plot(density(x), xlim=range(x, y, z))
axis(side=1, at=c(-1, 1))

lines(density(y), col="red")
lines(density(z), col="blue")