[R] ggplot with major and MINOR tick marks on a log scale
Sorkin, John
j@ork|n @end|ng |rom @om@um@ry|@nd@edu
Tue Jan 21 03:18:27 CET 2025
I have used ggplot to create a graph on which the y-axis is on the log scale. (see data and code, below.) I would like to add minor tick marks, which will also be on the log scale. The data and code are below. I hope somone can tell me how I can modify the ggplot code so it produces minor tick marks on a log scale.
Thank you,
John
PopByDayByAQIminus <- dget(
structure(list(Day = c("25", "25", "25", "25", "25", "25", "25",
"26", "26", "26", "26", "26", "26", "26", "27", "27", "27", "27",
"27", "27", "27", "28", "28", "28", "28", "28", "28", "28"),
AQI_Cat = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L,
3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L,
4L, 5L, 6L, 7L), levels = c("Good", "Moderate", "Unhealthy For Some",
"Unhealthy", "Very Unhealthy", "Hazardous1", "Hazardous2"),
class = "factor"), TotalPop = c(3751359, 35043, 4285,
11581, 26241, 17456, 18406, 3654557, 153002, 29954, 8452,
7719, 10687, 10430, 3654344, 104843, 57277, 24910, 15165,
4680, 13582, 3116416, 516504, 149029, 29640, 33468, 10862,
18882)),
class = "data.frame", row.names = c(NA, -28L)))
PopByDayByAQIminus
ggplot(PopByDayByAQIminus,aes(x=AQI_Cat,y=TotalPop/1000000,
group=Day,color=Day,shape=factor(Day),linetype = factor(Day)))+
labs(title=title,x="Air Quality Index") +
geom_point(size=4,alpha=0.7)+
geom_line(linewidth=1.5,alpha=0.3)+
theme(axis.text.x=element_text(angle = -15, hjust = 0))+
scale_y_continuous(trans='log10')
scale_y_continuous(breaks=seq(0,4000000,by=1000000))
John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;
Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center Geriatrics Research, Education, and Clinical Center;
PI Biostatistics and Informatics Core, University of Maryland School of Medicine Claude D. Pepper Older Americans Independence Center;
Senior Statistician University of Maryland Center for Vascular Research;
Division of Gerontology and Paliative Care,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382
More information about the R-help
mailing list