[R] Lines instead of points in a scatterplot

peter dalgaard pdalgd at gmail.com
Fri Sep 12 11:07:31 CEST 2014


The root cause is that column 1 is a factor. So what you get is really a set of parallel boxplots each based on one observation. 

plot.default() is one way out, but you may need to generate the x-axis labels yourself.

I.e.,

x <- factor(LETTERS[1:10])
y <- rnorm(10)
plot(x,y)
plot.default(x,y)

For full control, recode the factor to a numeric variable. 


On 12 Sep 2014, at 10:32 , Angel Rodriguez <angel.rodriguez at matiainstituto.net> wrote:

> 
> 
> Dear subscribers,
> 
> I have the following dataframe:
> 
>> aggr
>   child65$decedad       logit
> 1          [65,67)  0.00000000
> 10              67  0.00000000
> 2          [68,70) -0.06669137
> 3          [70,72) -0.71294981
> 4          [72,74) -0.59783700
> 5          [74,77) -1.08334482
> 6          [77,79) -1.88273125
> 7          [79,81) -1.21924028
> 8          [81,84) -1.94591015
> 9          [84,98] -1.65822808
> 
> When I write:
> 
>> plot(aggr)
> 
> I get the correct scatterplot, but points are substituted by horizontal lines. I prefer points.
> 
> If I write:
> 
>> plot(aggr, pch=1)
> 
> nothing changes
> 
>> plot(aggr[,1],aggr[,2])
> 
> nothing changes
> 
>> plot(aggr, type="p")
> 
> nothing changes
> 
> 
> Any idea?
> 
> Best regards,
> 
> Angel Rodr�guez-Laso
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd.mes at cbs.dk  Priv: PDalgd at gmail.com



More information about the R-help mailing list