On Aug 18, 2011, at 12:03 AM, Kota Hattori wrote:

Hi all,

I would like to ask a question with regard to R graphics. I am currently trying to add data points in boxplots using points(). In my script, I add up boxplots three times using add=TRUE. I use points() every time I add boxplots, and I see data points. However, I see all data points are clustered
at three specific points on x-axis; the locations of the data points
are not overlapping with intended boxplots. This is because I use
"at" in boxplot(). Is there any way that I can specify the locations of the
data points on x-axis? It would be great if there is something like
"at" in points(). Thank you for your help.


`boxplot` should return the values at which the midpoints of bars are being plotted. Take a look at str(<your-boxplot-call>). It's probably the $x component that you want to extract. `boxplot.stats` can also be used. You should either use plot=FALSE with boxplot or use boxplot.stats to gather the locations that can be used as x values (perhaps with jitter) in calls to points.

The scripts are not much use without data.)


Cheers,
Kota

The following is my script.


boxplot(F2.E$D.value ~ F2.E$consonant,
        main = "F2",
        ylim = c(-4,10),
        ylab = "Sensitivity (d')",
        xlab = "Discrimination Type",
        names = (c("E","E","E")),
        col = "light grey",
        border = "grey",
        boxwex = 0.2,
        at = 1:3 - 0.27
        )

points(jitter(rep(1:3, each = 8),0.1),
                unlist(split(F2.E$D.value,F2.E$consonant)),             
                cex = 0.5,
                pch = 16)


boxplot(F2.J.pre$D.value ~ F2.J.pre$consonant,
        add = TRUE,
        col = "light grey",
        border = "grey",
        names = (c("J Pre","J Pre","J pre")),
        boxwex = 0.2,
        at = 1:3 - 0)

points(jitter(rep(1:3, each = 28), 0.1),
                unlist(split(F2.J.pre$D.value,F2.J.pre$consonant)),             
                cex = 0.5,
                col = "blue",
                pch = 16)

boxplot(F2.J.post$D.value ~ F2.J.post$consonant,
        add = TRUE,
        col = "light grey",
        border = "grey",
        names = (c("J Post","J Post","J Post")),
        boxwex = 0.2,
        at = 1:3 + 0.27)

points(jitter(rep(1:3, each = 28), 0.1),
                unlist(split(F2.J.post$D.value,F2.J.post$consonant)),           
                cex = 0.5,
                col = "green",
                pch = 16)




David Winsemius, MD
West Hartford, CT

______________________________________________
R-help@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.

Reply via email to