0

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))
5
  • for geom_point() you should supply both x and y coordinates Commented Jun 9, 2015 at 11:06
  • If I add y=1 it returns no error but it also does not plot anything. Commented Jun 9, 2015 at 11:10
  • 1
    if you want to plot only these points you can assign y to be the same value of x so it will be something like this gap_plot <- ggplot() + geom_point(data=gaps, aes(x=gap_pos , y = gap_pos)) but I'm not sure if you want this result Commented Jun 9, 2015 at 11:14
  • It's the same result like adding y =1 it returns no error anymore but it does not plot anything :/ Commented Jun 9, 2015 at 11:16
  • 1
    No , It should work fine I think you're not executing the plot try to run gap_plot , check this code gap_plot <- ggplot() + geom_point(data=gaps, aes(x=gap_pos , y = gap_pos)) gap_plot Commented Jun 9, 2015 at 11:21

2 Answers 2

1

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 
Sign up to request clarification or add additional context in comments.

3 Comments

A simple y=1 will work - the 1 gets repeated. Normal R recycling rules dont apply though, it has to be length 1 or the same length as the data.
@Spacedman true and I edited. Interestingly the OP came up with that very solution themselves but reported it doesn't produce a plot. I guess the problem is that the plot was only produced but not called afterwards as pointed out in the comments above.
The problem was that my graphics device got a bug. After I called dev.close() your solutions worked fine
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.