I have a list of data points (0.2, 0.8, 0.95) that I want to plot on a line. I want to create a one-dimensional scale (vertical or horizontal) of this range of values with the names of those data points (apples, bananas, tomatoes) juxtaposed to the data points, which are positioned on t开发者_开发技巧he scale. I know there is a relatively easy function to this in a package but I can't find it anymore! Please help :).
Thank you, Annemarie
Not sure about a function to do this, closest I can think of if dotchart
but its not the same. However, how about this:
dat <- c(0.2,0.8,0.95)
names(dat) <- c("apples","bananas","tomatoes")
plot(c(1,1),range(dat),type="l",col="lightgrey",xlab="",xaxt="n")
points(rep(1,length(dat)),dat)
text(1,dat,names(dat),pos=4)
Which results in:
The first thing t come to my mind was to do it by hand:
plot(rep(1,3),c(0.2, 0.8, 0.95),ylim=c(0,1),axes=F,xlab="",ylab="",type="o",pch=19)
axis(side=2)
text(rep(1,3),c(0.2, 0.8, 0.95),c("apples", "bananas", "tomatoes"),pos=4,xpd=T)
because then you have full control. There is also a function called stripchart()
, that does 1-d plotting:
stripchart(c(0.2, 0.8, 0.95),vertical=T)
text(rep(1,3),c(0.2, 0.8, 0.95),c("apples", "bananas", "tomatoes"),pos=4)
neither is very beautiful, but you can take it from there.I found a handy function in the vegan library to do this:
x <- c(1,3.4,7,8,9,15,19)
names <- c("apple","pear","banana","grapefruit","orange","tomato","cucumber")
library(vegan)
linestack(x, names, side = "left")
Hopefully it is of use to somebody some time.
精彩评论