From: Robert Baer <rbaer_at_atsu.edu>

Date: Tue, 24 May 2011 08:41:10 -0500

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
**

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. Received on Tue 24 May 2011 - 13:46:15 GMT

Date: Tue, 24 May 2011 08:41:10 -0500

>> 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

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. Received on Tue 24 May 2011 - 13:46:15 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

Archive maintained by Robert King, hosted by
the discipline of
statistics at the
University of Newcastle,
Australia.

Archive generated by hypermail 2.2.0, at Tue 24 May 2011 - 17:30:09 GMT.

*
Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help.
Please read the posting
guide before posting to the list.
*