2) I don't get the desired results for: axis.title.y = theme_text(size = 10, face = "bold". In the output of the chart, the title of the y-axis is of the small fonti size and not emboldedened.Thanks,Pradip Muhuri#The code is shown below: setwd ('E:/Rdata')
load ("data_smk_spd.Rdata")
tempdata <- subset (data_smk_spd, add_col != "formr_smk")
tempdata$spd <- factor(tempdata$spd,levels=c ("No","Yes"),
labels=c('No SPD', 'SPD'), ordered=TRUE)
tempdata$age <- factor (tempdata$age, levels=c ('75+', '65-74', '45-64', '18-44'),
ordered=TRUE)
library(ggplot2)
p <- ggplot(data = tempdata, aes(x = age, y = est, fill = spd)) +
geom_bar(position="dodge", stat="identity", width=0.50) +
#geom_errorbar(aes(ymax = est + se,ymin = est),position=position_dodge(width=0.5), width=0.25)+
geom_text (aes(label=round(est,1)), position=position_dodge(width=0.9),
hjust=-.2, vsust=-.5, colour="red", size=8) +
scale_fill_manual(values=c("black", "#996633"))+
ylim (0,55)+
labs (x = " ", y= "Current Cigatette Use (%)", fill=" ")+
coord_flip()+
opts(axis.text.y=theme_text(size=24, hjust=1, face="bold"),
axis.title.y = theme_text(size = 10, face = "bold"),
axis.text.x=theme_text(size=24, hjust=0, face="bold"),
legend.text = theme_text(size= 20,hjust=0, face="bold"),
legend.position="bottom"
) print (p)
ggsave(file='curr_smk_spd.png', width=11, height=7)
Hi,I would appreciate if someone could advise me on resolving the following two issues:1) Although I got the bar chart correct, I could not figure out why I got the following message after each of the last two lines of the code in the console: ymax not defined: adjusting position using y instead
2) I don't get the desired results for: axis.title.y = theme_text(size = 10, face = "bold". In the output of the chart, the title of the y-axis is of the small fonti size and not emboldedened.
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
Hi Dennis,
My replacing the axis.title = element_text(size = rel(0.4)) with the axis.title.y = element_text(size = rel(0.4), colour="black") has given the desired results. Now, the y-axis (which is x-axis in the present cord_flip()ped chart ) is of large font size and emboldened.
The y-limit has also been expanded.
Thanks,
Pradip
Pradip K. Muhuri, PhD
Statistician
Substance Abuse & Mental Health Services Administration
The Center for Behavioral Health Statistics and Quality
Division of Population Surveys
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857
Tel: 240-276-1070
Fax: 240-276-1260
e-mail: Pradip...@samhsa.hhs.gov
The Center for Behavioral Health Statistics and Quality your feedback. Please click on the following link to complete a brief customer survey: http://cbhsqsurvey.samhsa.gov
I think you should be getting the following warning: “ymax not defined: adjusting position using y instead”.
To understand more about this warning, refer this ggplot2 group discussion specifically to Hadley’s comment at the bottom of this page: https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/PGzx4u6U84Y
I would suggest you to remove ylim (0,55) + and instead, aesthetically map the ymin to 0 and ymax to 60 (as Dennis suggested) in line 1. See the modified code. Let me know if your still getting this warning.
tempdata <- read.table("d1.txt", header = TRUE, sep = " ")
dim(tempdata)
tempdata$spd <- factor(tempdata$spd,
levels=c ("No","Yes"),
labels=c('No SPD', 'SPD'),
ordered=TRUE)
tempdata$age <- factor (tempdata$age,
levels=c ('75+', '65-74', '45-64', '18-44'),
ordered=TRUE)
library("ggplot2")
loadedNamespaces()
#[1] "base" "colorspace" "datasets" "dichromat" "digest" "ggplot2" "graphics" "grDevices"
# [9] "grid" "gtable" "labeling" "MASS" "memoise" "methods" "munsell" "plyr"
#[17] "proto" "RColorBrewer" "reshape2" "scales" "stats" "stringr" "tools" "utils"
p <- ggplot(data = tempdata, aes(x = age, y = est, ymin=0, ymax=60, fill = spd)) +
geom_bar(position="dodge", stat="identity", width=0.50) +
geom_text (aes(label=round(est,1)), position=position_dodge(width=0.9),
hjust=-.1, vjust=-.1, colour="red", size=8) +
scale_fill_manual(values=c("black", "#996633"))+
labs (x = " ", y= "Current Cigarette Use (%)", fill=" ")+
coord_flip()+
theme(text = element_text(size = 25, face = "bold"),
axis.text.x = element_text(vjust = 0, colour="black"),
axis.text.y = element_text(hjust = 1, colour="black"),
axis.title.y = element_text(size = rel(0.4), colour="black"),
axis.title.x = element_text( face = "plain"),
legend.text = element_text(size = rel(0.8), hjust = 0),
legend.position = "bottom")
print (p)
ggsave(file='test_curr_smk_spd.png', width=11, height=7)
HTH
Sathish
Hi Sathish,
With your modification of the code, that warning is gone! Excellent!
One question- Is there a way to reverse the legend key/text without changing the present order of the fill=” “?
Thank you so much!
Pradip
Pradip K. Muhuri, PhD
Statistician
Substance Abuse & Mental Health Services Administration
The Center for Behavioral Health Statistics and Quality
Division of Population Surveys
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857
Tel: 240-276-1070
Fax: 240-276-1260
e-mail: Pradip...@samhsa.hhs.gov
The Center for Behavioral Health Statistics and Quality your feedback. Please click on the following link to complete a brief customer survey: http://cbhsqsurvey.samhsa.gov
Hi,
Yes, that - guides(fill = guide_legend(reverse=TRUE)) - has worked.
Thank you so much!
Pradip
Pradip K. Muhuri, PhD
Statistician
Substance Abuse & Mental Health Services Administration
The Center for Behavioral Health Statistics and Quality
Division of Population Surveys
1 Choke Cherry Road, Room 2-1071
Rockville, MD 20857
Tel: 240-276-1070
Fax: 240-276-1260
e-mail: Pradip...@samhsa.hhs.gov
The Center for Behavioral Health Statistics and Quality your feedback. Please click on the following link to complete a brief customer survey: http://cbhsqsurvey.samhsa.gov