Question

I'm having some trouble with qplot in R. I am trying to plot data from a data frame. When I execute the command below the plot gets bunched up on the left side (see the image below). The data frame only has 963 rows so I don't think size is the issue, but I can use the same command on a smaller data frame and it looks fine. Any ideas?

library(ggplot2)
qplot(x=variable,
   y=value,
   data=data,
   color=Classification,
   main="Average MapQ Scores")

Or similarly:

ggplot(data = data, aes(x = variable, y = value, color = Classification) +
  geom_point()

enter image description here

Was it helpful?

Solution

Your column value is likely a factor, when it should be a numeric. This causes each categorical value of value to be given its own entry on the y-axis, thus producing the effect you've noticed.

You should coerce it to be a numeric

data$value <- as.numeric(as.character(data$value))

Note that there is probably a good reason it has been interpreted as a factor and not a numeric, possibly because it has some entries that are not pure numeric values (maybe 1,000 or 1000 m or some other character entry among the numbers). The consequence of the coercion may be a loss of information, so be warned or cleanse the data thoroughly.

Also, you appear to have the same problem on the x-axis.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top