R: ggplot2: Unable to plot points from a data.frame

1.8k Views Asked by At

So I want to do a simple plot where the following x-coordinates should be plotted as points. This is what my data.frame looks like:

   gap_pos
1 50646312
2 50647076
3 50647511
4 50647512
5 50647513
6 50647546

Now I have tried to do it as simple as possible:

gap_plot <- ggplot() + geom_point(data=gaps, aes(x=gap_pos))

Then the following error occurred:

Error in exists(name, envir = env, mode = mode) : 
argument "env" is missing, with no default

What can I do about this? I am totally stuck.

Edit:

The following two lines do not return an error but still do not plot anything.

gap_plot <- ggplot() + geom_point(data=gaps, aes(x=gap_pos , y = gap_pos))
gap_plot <- ggplot() + geom_point(data=gaps, aes(x=gap_pos , y = 1))
2

There are 2 best solutions below

3
On BEST ANSWER

This should work

gaps = data.frame(gap.pos = c(50646312, 50647076, 50647511, 50647512, 50647513, 50647546))
gap_plot <- ggplot(gaps) + geom_point(aes(x=gap.pos, y=1))

you have to call the plot you produced to actually see the plot

gap_plot 
0
On

You have to give a y aesthetic for points. I'd add a factor with a single level to make a nice y axis:

> gap=data.frame(gap_pos=c(50646312, 50647076, 50647511, 50647512, 50647513, 50647513, 50647546))
> gap$data=factor("Data")
> ggplot() + geom_point(data=gap, aes(x=gap_pos, y=data))+ylab("")

Which gives: single Y plot