The problem you're having is that you've mapped x = genre
. Thus, genre
gets converted to a factor and then plotted at either 1
or 2
.
Instead, what you want to do is have the data plotted at a random point on the x-axis
. A simple way to do this is to randomly sample 1:nrow(playlist)
like this:
ggplot(data = playlist, aes(x = sample(1:nrow(playlist),nrow(playlist)),
color = genre, y = danceability)) +
geom_point(aes(col = genre)) + labs(x = "data")
Note that you no longer need geom_jitter
.
Data:
playlist <- structure(list(danceability = c(0.683, 0.768, 0.693, 0.765, 0.506,
0.809, 0.628, 0.556, 0.72, 0.706, 0.414, 0.448, 0.687, 0.747,
0.532, 0.483, 0.491, 0.224, 0.666, 0.416, 0.44, 0.362, 0.28,
0.42, 0.115, 0.35, 0.519, 0.538, 0.507, 0.261), genre = c("pop",
"pop", "pop", "pop", "pop", "pop", "pop", "pop", "pop", "pop",
"pop", "pop", "pop", "pop", "pop", "heavy-metal", "heavy-metal",
"heavy-metal", "heavy-metal", "heavy-metal", "heavy-metal", "heavy-metal",
"heavy-metal", "heavy-metal", "heavy-metal", "heavy-metal", "heavy-metal",
"heavy-metal", "heavy-metal", "heavy-metal")), row.names = c(NA,
-30L), class = "data.frame")
Note: This data was derived by optical character recognition from your screen shot, please excuse any errors.