[R] plot xaxp issue

Elaine Kuo elaine.kuo.tw at gmail.com
Mon Jan 7 13:11:54 CET 2013


Thanks a lot.
Please kindly indicate the meaning of the c(8,7).

> together <- rbind(boy, girl)
> together$sex <- factor(rep(c("boy", "girl"), c(8,7)))

Elaine

On Mon, Jan 7, 2013 at 4:55 PM, PIKAL Petr <petr.pikal at precheza.cz> wrote:
> Hi
>
> Instead of two plots with par(new = TRUE) try to put boys and girls together (quite natural thing, they will be pleased 8-)
>
> together <- rbind(boy, girl)
> together$sex <- factor(rep(c("boy", "girl"), c(8,7)))
>
> plot(together$body_length, together$body_weight, ...., col=c("firebrick3","saddlebrown")[as.numeric(together$sex)], ....)
>
> Regards
> Petr
>
>
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Elaine Kuo
>> Sent: Monday, January 07, 2013 9:27 AM
>> To: r-help at r-project.org
>> Subject: [R] plot xaxp issue
>>
>> Hello,
>>
>> I have data of Body length and Body weight of 8 boys and 7 girls.
>>
>> I want to draw the plot of Body length (for X) and Body weight (for Y)
>> based on sex.
>> Then the two plots want to be overlapped for comparison.
>>
>> I used the code below but found the unit length of X axis of boy and
>> girl plot are not the same.
>> For instance, the length between 0 and 1 of boy plot is larger than
>> that in girl plot.
>> The same thing happened to Y axis as well.
>> (In other words, though axap and yaxp were set to be the same, the
>> display were not the same.)
>>
>> Please kindly advise correction of the code.
>> Thank you.
>>
>> Elaine
>>
>> # plot code
>>     boy<-read.csv("H:/boy_data.csv",header=T)
>>     girl<-read.csv("H:/girl_data.csv",header=T)
>> par(mai=c(1.03,1.03,0.4,0.4))
>>
>>     plot(boy$body_length, boy$body_weight,
>>     xlab=" body_length (cm)",
>>     ylab=" body_weight  ( kg )",
>>     xaxp=c(0,200,4),
>>     yaxp=c(0,100,4),
>>     type="p",
>>     pch=1,lwd=1.0,
>>     cex.lab=1.4, cex.axis=1.2,
>>     font.axis=2,
>>     cex=1.5,
>>     las=1,
>>     bty="l",col="firebrick3")
>>
>>     boyline<-lm(body_weight ~ body_length, boy)
>>     summary(boyline)
>>     abline(boyline,col="firebrick3",lwd=2)
>>
>>     #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>>   # graph
>>     par(mai=c(1.03,1.03,0.4,0.4))
>>
>>     par(new=T)
>>
>>     plot(girl$body_length, girl$body_weight,
>>     xlab=" body_length (cm)",
>>     ylab=" body_weight  ( kg )",
>>     xaxp=c(0,200,4),
>>     yaxp=c(0,100,4),
>>     type="p",
>>     pch=1,lwd=1.0,
>>     cex.lab=1.4, cex.axis=1.2,
>>     font.axis=2,
>>     cex=1.5,
>>     las=1,
>>     bty="l",col="saddlebrown")
>>
>>
>>     girlline<-lm(body_weight~ body_length, girl)
>>     summary(girlline)
>>     abline(girlline,col="saddlebrown",lwd=2)
>>
>> ______________________________________________
>> 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.




More information about the R-help mailing list