Home » R » ggplot2 » pch symbols

pch symbols

I often have used simple code like this to remind myself which number corresponds to which pch character:

par(mar=c(4,1,1,1))
plot(x, y, type="n", ylab="", xlab="pch", axes=FALSE)
box()
axis(1)
abline(v=1:25,lty=3,col="grey")
points(1:25,rep(1,25),pch=1:25)

p2.jpg

I wondered what it would take to do the same in ggplot2. The amount of typing required to remove (most of) the y axis kinda annoys me, but otherwise, it’s quite nice:

ggplot(data.frame(x=x,y=y), aes(x=x,y=y,pch=as.factor(x))) +
  geom_point() +
  xlab("pch") + ylab("") +
  scale_shape_manual(values=1:25) +
  opts(legend.position="none",
       axis.title.y = theme_blank(),
       axis.text.y =  theme_blank() )

p3.jpg

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s