下面是一个几乎完全符合我想要的情节的示例代码.根据下面定义的minor_breaks,我想要添加的唯一内容是x轴上的刻度线(与主刻度相同的大小).
df <- data.frame(x = c(1900,1950,2000), y = c(50,75,60))
p <- ggplot(df, aes(x=x, y=y))
p + geom_line() +
scale_x_continuous(minor_breaks = seq(1900,2000,by=10), breaks = seq(1900,2000,by=50), limits = c(1900,2000), expand = c(0,0)) +
scale_y_continuous(breaks = c(20,40,60,80), limits = c(0,100)) +
theme(legend.position="none", panel.background = element_blank(),
axis.line = element_line(color='black'), panel.grid.minor = element_blank())
Run Code Online (Sandbox Code Playgroud)
在此先感谢, - .JT
我正在尝试为黑白出版物制作一些图形,我在使用轴时遇到了一些问题.
我需要在轴(而不是网格)中绘制数据的子图,并且我通过使用annotation_logticks(base=2, sides="trbl")with base 2 找到了一个技巧,因为我的数据与日志无关.
但这似乎不适用于y轴,它采用日期格式类型(xts).
到目前为止我得到的图是下面的图,我需要的是删除背景网格(该部分应该很容易)并在y轴上添加刻度(这对我来说是困难的部分).

这是我用来做图表的代码:
ratio_plot_start_time = "01:45"
ratio_plot_end_time = "02:10"
channelNo = 1
p <- ggplot(onsetratios, aes(x=ratio*100, y=onset)) + geom_point(aes(y=onset))
p <- p + ylim(as.POSIXct(paste(date, ratio_plot_start_time, sep=" ")), as.POSIXct(paste(date, ratio_plot_end_time, sep=" ")))
p <- p + geom_errorbar(aes(ymin=onset-error, ymax=onset+error), width=0.0)
p <- p + xlab(expression("percent of peak counts"))+ ylab(expression("UT Time (2012 May 17)")) + theme(aspect.ratio = 2/(1+sqrt(5)))
p <- p + theme_bw(base_size = 14, base_family = "Helvetica") + annotate("text",x=max(onsetratios$ratio),y=as.POSIXct(paste(date, ratio_plot_end_time, sep=" ")),vjust=4,hjust=2,label=paste("F", channelNo, "'")) …Run Code Online (Sandbox Code Playgroud)