Jitter scatterplot value positions with value labels in R using ggplot2

The following R code creates a scatterplot using ggplot2. Points on this plot are represented by identification numbers. The jitter option removes overlap between these plotted values.

#### Attach R libraries

#### Generate random data set 
theData <- data.frame(id=1:20, xVar=sample(1:4, 20, replace=TRUE), yVar=sample(1:4, 20, replace=TRUE))

#### Plot scatterplot
p <- ggplot(theData)
p + theme_bw() + geom_text(aes(x=xVar,y=yVar,label=id),size=3,position=position_jitter(w=.2, h=.2))

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