pradip...@samhsa.hhs.gov
unread,Jan 25, 2013, 2:37:18 PM1/25/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to ggp...@googlegroups.com, pradip...@samhsa.hhs.gov
Hello,
Using the reproducible example appended below, I have drawn a bar chart. But, the issues are as follows:
1) I am not getting the desired effect of the following on the chart (i.e., the font is not large enough, not black colored, not bold).
geom_text (aes(label=est, size=20, hjust=-.1, colour="black",face="bold")) +
2) I could not figure out how to modify the code so that the label is printed on the chart, retaining one position after the decimal like 67.0 rather than 67. I have tried formatC(), which gives me the desired result but messes up the y.axis.text. Is there an alternative to formatC(), which I could use for printing one place after the decimal?
Any suggestions toward resolving these issues would be appreciated.
regards, and thanks in advance.
Pradip Muhuri
#### reproducible example is given below - both code and data
setwd ("E:/")
data <- read.csv(text =
"Fairly/Very Easy to Obtain Mrj for Youth,51.4,0.17
Low Level of Parental Monitoring,13.7,0.12
Parents Not Strongly Disapprv Mon Mrj Use,7.2,0.09
Parents Not Strongly Disapprv Daily Alc Use,10.8,0.11
10+ Conflicts with Parents Past 12 M,23.4,0.15
High Level of Antisocial Behavior,17.3,0.13
Y Not Strongly Disapprv Peer Mon Mrj Use,33.8,0.17
Y Not Strongly Disapprv Peer D Alc Use,32.4,0.16
Friends Not Strongly Disapprv Y Mon Mrj Use,31.6,0.16
Friends Not Strongly Disapprv Y Daily Alc Use,35.5,0.17
Less than Great Risk of Y Mon Mrj Use,65.8,0.17
Less than Great Risk of Y Wkly Mrj Use,46.0,0.18
Less than Great Risk of Y 5+ Alc 1 or 2 Times a Wk,61.1,0.17
Less than Great Risk of Youth 4-5 Alc Drinks Daily,36.4,0.17
High Level of Risk-Taking Proclivity,11.7,0.10
Moved 2+ Times in the Past 5 Years,24.8,0.18
Most/All Students in Same Grade ... Use Mrj,24.2,0.16
Most/All Students in Same Grade ... Use Alc,44.7,0.18
Most /All Students Get Intox Alc Wkly,18.6,0.14
GPA D or Below in Last Grading Period,6.5,0.09"
, sep=",", dec=".", colClasses = c("factor", "numeric", "numeric") )
names (data) <- c ("rp_rev_f", "est", "se" )
head (data)
library("ggplot2")
loadedNamespaces()
p <- ggplot( data, aes(x=reorder(rp_rev_f,est), y=est, fill="#990000") )+
geom_bar(stat="identity", width=.50) +
geom_text (aes(label=est, size=20, hjust=-.1, colour="black",face="bold")) +
scale_fill_manual(values="#990000")+
ylim(0,90)+
xlab("")+
ylab(" ")+
coord_flip ()+
theme(text = element_text(size=25,face = "bold"),
axis.text.x = element_text(hjust=1, face="bold"),
axis.text.y = element_text(hjust=1, face="bold"),
axis.title.y = element_text(hjust=1, face="bold"),
axis.title.x = element_text( vjust=1, face="bold"),
legend.position="none" )
print (p)
ggsave(file='prevalence_r.png', width=11, height=7)