[英]R: ggplot2: Unable to plot points from a data.frame
So I want to do a simple plot where the following x-coordinates should be plotted as points. 因此,我想做一个简单的绘图,其中应将以下x坐标绘制为点。 This is what my data.frame looks like:
这是我的data.frame的样子:
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))
You have to give a y
aesthetic for points. 您必须给点以
y
美感。 I'd add a factor with a single level to make a nice y
axis: 我将添加一个具有单个水平的因子以构成一个漂亮的
y
轴:
> 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: 这使:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.