R 在ggplot2中使用scale_y_log10()进行轴刻度偏差和标记
我正试图做一个: 在y轴而不是x轴上使用对数刻度。我已经能够用以下代码生成此代码:R 在ggplot2中使用scale_y_log10()进行轴刻度偏差和标记,r,ggplot2,axes,R,Ggplot2,Axes,我正试图做一个: 在y轴而不是x轴上使用对数刻度。我已经能够用以下代码生成此代码: setwd('/Users/marleyjarvis/Desktop/') CompMero=read.csv("CompMero.csv") library(ggplot2) library(scales) #for the trans and format functions attach(CompMero) ggplot(CompMero, aes(x=station, y=Mean)) + geom
setwd('/Users/marleyjarvis/Desktop/')
CompMero=read.csv("CompMero.csv")
library(ggplot2)
library(scales) #for the trans and format functions
attach(CompMero)
ggplot(CompMero, aes(x=station, y=Mean)) +
geom_errorbar(aes(ymin=Mean-StErr, ymax=Mean+StErr), colour="black", width=.1) +
geom_point(size=3) +
xlab("Tow station with respect to foam line and front") +
ylab(expression(paste(Mean~no~per~m^3))) +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
) +
scale_x_continuous(breaks=c(1:3), labels=c("Inshore", "Foam line", "Offshore")) +
annotation_logticks(sides = "l") + #log ticks only on y!!!!
scale_y_log10(breaks = trans_breaks("log10", n=6, function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)),
minor_breaks = log10(5) + -1:3) +
coord_fixed()
其结果是:
我的问题是:
关于fig,有两件事我还没有弄清楚如何改变(尽管我花了几个小时搜索文档、网络等)
CompMero
编辑:样本数据在名称为stationID、station、Mean、StErr的列中站点ID:泡沫管线,近海,近海 车站:2、1、3 平均数:3419.401,35.56681,70.47807 斯特尔:1888.509、11.55935、40.04964
非常感谢您的帮助和指点。我花了相当多的时间阅读文档和帮助文件,搜索过去的问题,但没有能够解决这两个问题。如果有人能给我指出正确的方向,我将不胜感激。如果其他人偶然发现这个问题并可能从中受益,我已经制定了轴标签,并使用以下代码消除了那些令人讨厌的“中间”刻度,这些刻度未对齐:
ggplot(df, aes(x=station, y=Mean)) +
geom_errorbar(aes(ymin=Mean-StErr, ymax=Mean+StErr), colour="black", width=.1) +
geom_point(size=3) +
xlab(NULL) +
ylab(NULL) +
theme_bw() +
theme(
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
) +
scale_x_continuous(expand=c(.2,0), breaks=c(1:3), labels=c("IN", "FL", "OFF")) +
annotation_logticks(sides = "l") + #log ticks only on y!!!!
scale_y_log10() +
theme(axis.text.x=element_text(size=16))+
theme(axis.text.y=element_text(size=16))