2

I have a datset and am trying to have a plot with probability. My codes go like this: vp <- table(raising_vowels$realization, raising_vowels$pattern)

vp

Then, I tried to have a barplot via:

barplot(prop.table(vp, 2), main='Convergence affected by pattern',
    xlab='Pattern', ylab='Convergence Probability')

This gave me an image with no legend.

I want a legend outside the plot. I tried this code:

barplot(prop.table(vp, 2), main='Convergence affected by pattern',
xlab='Pattern', ylab='Convergence Probability', legend("right", inset=.05, 
title="Realization", c("CA","MA"),horiz=TRUE)))

but it did not work. Q: How can I have the legend outside the plot? I tried some websites but could not get a different result. There could be missing packages.

  • consider using the [`ggplot2` library](https://cran.r-project.org/web/packages/ggplot2/index.html). Read [The Quick-R tutorial: `ggplot2`](http://statmethods.net/advgraphs/ggplot2.html) and [`ggplot2`: Cheatsheet for Barplots](http://www.r-bloggers.com/ggplot2-cheatsheet-for-barplots/) – Barranka Aug 17 '15 at 23:20
  • I'm not familiar with a `barplot` version that actually takes the return value of `legend(...)` as an argument; in this code, `barplot` thinks that the return from `legend` (which is a list, btw) is supposed to be `width` which is supposed to be an integer. First, I recommend you first read `help(barplot)`. Second, I recommend @MichaelChirico's link, including reading the relevant paragraph in `help(par)` on `xpd` (which is a very daunting help page ... don't try to get it all at once). – r2evans Aug 18 '15 at 06:19

0 Answers0