1

I have a question related to this question.

I plotted my data in ggplot2, but I'd like to have more space between the points and also between the groups. I'm plotting ESM data over 17 days, and I want to show in a plot how a person's emotion changes during the day when he/she rates his/her emotion.

Thus, I want to plot only the points (no line), I want some space between the points so that one can see which point was entered first, and I want more space between the days (x-variable) so that it's visible which points belong to which day.

example data:

beep <- c(74.50, 77.50, 89.50, 75.25, 58.25, 81.25, 88.75, 89.25, 74.25, 71.00)
days <- c(1, 1, 1, 2, 2, 3, 3, 4, 4, 4)
df <- as.data.frame(cbind(days, beep))
ggplot(df, aes(days, beep)) + geom_point()

In this MWE, ggplot stacks the data points in one vertical line, whereas I'd like to see which datapoint came first on that particular day (I hope I explain this clear).

Community
  • 1
  • 1
Jolanda Kossakowski
  • 451
  • 2
  • 6
  • 14
  • 1
    What is the `ggplot` command you used to plot this data? – MrFlick Jun 04 '14 at 18:25
  • Please read the info about [how to ask a question](http://stackoverflow.com/help/how-to-ask) and how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). This will make it much easier for others to help you. – Jaap Jun 04 '14 at 18:29
  • When I use your `ggplot` command, the points have enough space inbetween them. – Jaap Jun 04 '14 at 18:40

1 Answers1

2

If you know the "temporal spacing" of you observation more accurately you could add this directly to the days vector. For instance if the measurements are evenly spaced throughout the day you could set

days <- c(1, 1+1/3, 1+2/3, 2, 2+1/2, 3, 3+1/2, 4, 4+1/3, 4+2/3)

You could easily automate the process of making this vector from your original vector. However if you do not have this information, but only know the order and day of the observations, why not let the x-axis convey the ordering and find another mean of visualizing the change of day. For instance using the background colour.

beep <- c(74.50, 77.50, 89.50, 75.25, 58.25, 81.25, 88.75, 89.25, 74.25, 71.00)
days <- c(1, 1, 1, 2, 2, 3, 3, 4, 4, 4)
order <- c(1:10)
df <- as.data.frame(cbind(days, beep,order))
ggplot(df, aes(order, beep,xmin=order-0.5,xmax=order+0.5,ymin=-Inf,ymax=Inf, fill=as.factor(days%%2))) + 
  geom_rect(aes(alpha=0.2))  +
  geom_point() +theme_bw() +
  scale_x_continuous(breaks=1:10) + guides(alpha=F,fill=F)

enter image description here

Tobias Madsen
  • 857
  • 8
  • 10