[R] barplot beside=TRUE - values differ on scales

Duncan Murdoch murdoch.duncan at gmail.com
Wed Oct 12 19:25:39 CEST 2016


On 12/10/2016 12:59 PM, Adrian Johnson wrote:
> Thanks Duncan.
> I am sorry I cannot scale second row (d[2,]).
> I was looking for a way to plot d[2,] values next to d[1,]  with a
> right side axis=4  on right side. -2,-1,0,1,2

That doesn't really make graphical sense, but you can use any 
transformation you like, not just a rescaling.  If you want -2 for the 
2nd row to be the same as 0 on the first row, just work out the 
transformation that achieves that, and use it.

Duncan Murdoch
> thanks
> Adrian
>
> On Wed, Oct 12, 2016 at 12:42 PM, Duncan Murdoch
> <murdoch.duncan at gmail.com> wrote:
> > On 12/10/2016 12:20 PM, Adrian Johnson wrote:
> >>
> >> Dear group,
> >> I have been struggling to barplot two different measurements from one
> >> subject. These two measures differ in range.  I want to plot row 1
> >> axis on left side and row 2 values on right side.
> >>
> >> For a given column I want to plot GN and CN next to each other.
> >>
> >> my dput code is below
> >> :
> >>
> >> structure(c(112L, 0L, 579L, 1L, 131L, 1L, 2234L, 2L, 2892L, 1L,
> >> 528L, 0L, 582L, 2L), .Dim = c(2L, 7L), .Dimnames = list(c("GN",
> >> "CN"), c("DC5", "DC8", "DC14", "DC18", "DC19", "DC20", "DC23"
> >> )))
> >>
> >>
> >> As you can see:
> >>     DC5 DC8 DC14 DC18 DC19 DC20 DC23
> >> GN 112 579  131 2234 2892  528  582
> >> CN   0   1    1    2    1    0    2
> >>
> >> GN values are range from 100 - 3000
> >> while CN are always -2 or -1 or 0 or 1 or 2
> >>
> >> Also I cannot log GN values and plot because a difference in 100 units
> >> also matters in my experiment.
> >>
> >> Any help would be greatly appreciated.
> >
> >
> > I would simply rescale one row and add a second axis.  For example, if d
> > holds your matrix:
> >
> > scale <- max(d[1,])/max(d[2,])
> > adjusted <- d
> > adjusted[2,] <- scale*adjusted[2,]
> > barplot(adjusted, beside = TRUE)
> > ticks <- pretty(d[2,])
> > axis(side = 4, at = ticks*scale, labels = ticks)
> >
> > Duncan Murdoch
> >
> >



More information about the R-help mailing list