[R] Data values on graphics

Zeki Çatav zcatav at gmail.com
Tue May 24 18:55:58 CEST 2011


Sal, 2011-05-24 tarihinde 08:41 -0500 saatinde, Robert Baer yazdı:
> >> zcatav wrote:
> >>>
> >>> How can i add data values or proportion values on bar or pie charts?
> >>>
> >> You can add any text or numbers to any place of a graph with this 
> >> command:
> >>> text(45,20,"some text")
> >> where: 45 is position on the X-axis and 20 - on the Y. Note that numbers
> >> denote the MIDDLE of the text,not its bottom-left corner. Must work
> >> perfectly for barplots, although not sure about pie-charts.
> >>
> >
> > It's o.k. to add text,but i mean data values representing colon.
> > Let's we have following table;
> >   A   B
> > 1 2   3
> > 2 4   5
> > 3 3   6
> >
> > I want to see these values (or % values) on representing bar. And if
> > possible R makes it automatically.
> > Thanks.
> 
> Maybe this example will help for barplots.
> 
> df = structure(list(A = c(2L, 4L, 3L), B = c(3L, 5L, 6L)),
>       .Names = c("A", "B"), class = "data.frame",
>       row.names = c("1", "2", "3"))
> 
> vec = c(mean(df$A), mean(df$B)) #Bars assumed to be column means
> 
> # bp stores the x locations for text
> bp = barplot(vec)
> 
> # At top of bars
> text(bp, vec, vec, xpd = T)         # xpd = T prevents clipping
> 
> # Alternative with txt placement cleaner output
> text(bp, c(2, 2), round(vec,1))
> 
> # Doing percents
> pc = 100*vec/sum(vec)
> text(bp, c(1, 1), paste(round(pc,1), '%', sep=' '))
> 
> 
> 
> ------------------------------------------
> Robert W. Baer, Ph.D.
> Professor of Physiology
> Kirksville College of Osteopathic Medicine
> A. T. Still University of Health Sciences
> 800 W. Jefferson St.
> Kirksville, MO 63501
> 660-626-2322
> FAX 660-626-2965

Thanks a lot. This is, what i want.

-- 
Zeki Çatav
http://zekicatav.tyih.gov.tr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Bu dijital olarak imzalanm?? ileti par?as?d?r
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110524/3a276f89/attachment.bin>


More information about the R-help mailing list