Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot one variable in ggplot?

Tags:

plot

r

ggplot2

I'm searching but still can't find an answer to a quite simple question - how can we produce a simple dot plot of one variable with ggplot2 in R?

with plot command this is very simple:

plot(iris$Sepal.Length, type='p') 

But when I'm trying to pass one variable to qplot and specifying geom="point", I'm getting an error "Error in UseMethod("scale_dimension")".

Simple one-variable plot

How can we make a plot like this but with ggplot2?

like image 599
annndrey Avatar asked Dec 12 '12 10:12

annndrey


People also ask

What does %>% do in Ggplot?

%>% is a pipe operator reexported from the magrittr package. Start by reading the vignette. Adding things to a ggplot changes the object that gets created. The print method of ggplot draws an appropriate plot depending upon the contents of the variable.


1 Answers

You can manually create an index vector with seq_along.

library(ggplot2)  qplot(seq_along(iris$Sepal.Length), iris$Sepal.Length) 

enter image description here

like image 114
Sven Hohenstein Avatar answered Sep 22 '22 07:09

Sven Hohenstein