R:在ggplot中使用log10比例的y轴自定义记号标记

R:在ggplot中使用log10比例的y轴自定义记号标记,r,ggplot2,scale,axis,R,Ggplot2,Scale,Axis,当我使用log10刻度时,我很难创建一个漂亮的y轴。。我试过我在电视上看到的东西,但他们给了我一个混乱的情节。 这是我想要的y轴: 我需要在scale\u y\u log10()函数中提供什么类型的参数才能获得所需的结果?非常感谢您的任何帮助或建议!提前谢谢! 我正在使用的代码: library(ggplot2) box_whisk_graph<-ggplot(data = box_fresh_chloride, aes(x = factor(year), y = val)) +

当我使用log10刻度时,我很难创建一个漂亮的y轴。。我试过我在电视上看到的东西,但他们给了我一个混乱的情节。 这是我想要的y轴:

我需要在
scale\u y\u log10()
函数中提供什么类型的参数才能获得所需的结果?非常感谢您的任何帮助或建议!提前谢谢! 我正在使用的代码:

library(ggplot2)

box_whisk_graph<-ggplot(data = box_fresh_chloride, aes(x = factor(year), y = val)) +
  geom_boxplot(coef=5) +
  geom_hline(aes(yintercept = 230,colour="red"),size=1.3)+
  geom_hline(aes(yintercept = 860,colour="#FF3333"),size=1.3,linetype="dotted")+
     scale_y_continuous(trans="log10",limits=c(10,2000),breaks=c(10,2000,100))
box_fresh_chloride = structure(list(orgid = c("USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", 
"USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", 
"USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ", 
"USGS-NJ", "USGS-NJ", "USGS-NJ", "USGS-NJ"), locid = c("USGS-01482500", 
"USGS-0146453250", "USGS-01392150", "USGS-01411035", "USGS-01411466", 
"USGS-01411444", "USGS-01407821", "USGS-01464527", "USGS-01405340", 
"USGS-01409387", "USGS-01403385", "USGS-01467005", "USGS-01409815", 
"USGS-0146708240", "USGS-01411110", "USGS-01400000", "USGS-01467150", 
"USGS-01391500", "USGS-01467010", "USGS-0140940950"), stdate = structure(c(16394, 
16610, 16328, 16583, 16602, 16602, 16602, 16588, 16588, 16588, 
16588, 16589, 16590, 16590, 16594, 16589, 16589, 16595, 16602, 
16583), class = "Date"), sttime = structure(c(35100, 39600, 38400, 
35100, 43200, 37800, 36900, 33600, 45000, 46200, 40500, 47400, 
42300, 36000, 39600, 40500, 34200, 39600, 34200, 45000), class = c("hms", 
"difftime"), units = "secs"), charnam = c("Chloride", "Chloride", 
"Chloride", "Chloride", "Chloride", "Chloride", "Chloride", "Chloride", 
"Chloride", "Chloride", "Chloride", "Chloride", "Chloride", "Chloride", 
"Chloride", "Chloride", "Chloride", "Chloride", "Chloride", "Chloride"
), val = c(23.6, 221, 144, 10.8, 10.5, 5.76, 37.1, 22.5, 78.3, 
8.67, 51.5, 17.9, 4.48, 55.8, 16.1, 62.9, 67.6, 187, 47.5, 27.7
), valunit = c("mg/l", "mg/l", "mg/l", "mg/l", "mg/l", "mg/l", 
"mg/l", "mg/l", "mg/l", "mg/l", "mg/l", "mg/l", "mg/l", "mg/l", 
"mg/l", "mg/l", "mg/l", "mg/l", "mg/l", "mg/l"), swqs = c("FW2-NT", 
"FW2-NT", "FW2-NT", "PL", "FW2-NT", "PL", "FW2-NT", "FW2-NT", 
"FW2-NT", "PL", "FW2-NT", "FW2-NT", "PL", "FW2-NT", "PL", "FW2-NT", 
"FW2-NT", "FW2-NT", "FW2-NT", "PL"), WMA = c(17L, 20L, 4L, 15L, 
17L, 16L, 12L, 20L, 9L, 14L, 9L, 19L, 14L, 18L, 15L, 8L, 18L, 
4L, 19L, 14L), year = c(2014, 2015, 2014, 2015, 2015, 2015, 2015, 
2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 2015, 
2015, 2015)), .Names = c("orgid", "locid", "stdate", "sttime", 
"charnam", "val", "valunit", "swqs", "WMA", "year"), row.names = c(NA, 
-20L), class = c("tbl_df", "tbl", "data.frame"))

解决此问题的一种方法是手动构建一个“中断”值向量,然后将这些值提供给
scale\u y\u continuous()
函数调用

breaks_vec = rep(seq(from=1, to=10), 3) * 10^rep(seq(from=1, to=3), each=10)

box_whisk_graph <- ggplot(data=box_fresh_chloride, aes(x=factor(year), y=val)) +
                   theme_bw() +
                   geom_boxplot(coef=5) +
                   geom_hline(yintercept=230, colour="red", size=1.3)+
                   geom_hline(yintercept=860, colour="#FF3333", size=1.3, 
                              linetype="dotted")+
                   scale_y_continuous(trans="log10", limits=c(10,2000), 
                                      breaks=breaks_vec, minor_breaks=NULL)
breaks_vec=rep(seq(from=1,to=10),3)*10^rep(seq(from=1,to=3),每个=10)

我试过我在电视上看到的东西,但他们给了我一个混乱的情节。。。请提供您尝试过的代码,以及为什么它的结果不是您期望的结果。也许您可以向问题中添加示例数据?您是否尝试过
+scale\u y\u log10(breaks=…)
?可能有帮助:,您的命令只输出
\n范围:\n限制:1--3.3
,因为前面没有任何内容。请添加示例数据和缺少的代码。@r2evans我包括示例数据和代码。