[R] Lines instead of points in a scatterplot

Angel Rodriguez angel.rodriguez at matiainstituto.net
Fri Sep 12 11:23:55 CEST 2014


Thank you Peter. plot.default works perfectly.

I'm puzzled now with the first column of the dataframe aggr. 

aggr comes from:

aggr<-summarize(child65$benvii, by=child65$decedad, FUN=mean, na.rm=TRUE)

If I write:

> aggr[,1]
 [1] [65,67) 67      [68,70) [70,72) [72,74) [74,77) [77,79) [79,81) [81,84) [84,98]
attr(,"label")
[1] child65$decedad
Levels: [65,67) 67 [68,70) [70,72) [72,74) [74,77) [77,79) [79,81) [81,84) [84,98]
> aggr[,2]
    [65,67)          67     [68,70)     [70,72)     [72,74)     [74,77)     [77,79)     [79,81)     [81,84) 
 0.00000000  0.00000000 -0.06669137 -0.71294981 -0.59783700 -1.08334482 -1.88273125 -1.21924028 -1.94591015 
    [84,98] 
-1.65822808 
attr(,"label")
[1] "child65$benvii"
attr(,"class")
[1] "labelled" "array"   


So, it's like if the first column does not exist. It does not even have a name.

Angel




-----Mensaje original-----
De: peter dalgaard [mailto:pdalgd at gmail.com]
Enviado el: vie 12/09/2014 11:07
Para: Angel Rodriguez
CC: R-help at r-project.org
Asunto: Re: [R] Lines instead of points in a scatterplot
 
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










	[[alternative HTML version deleted]]



More information about the R-help mailing list