右 |图表2 | (删除刻度线+删除面板边框)但保留轴线

R | ggplot2 | (remove tick marks + remove panel border) but keep axis lines

新手请多多关照! :)

我正在处理以下数据集和 R 脚本:

#Create pvalue ranges
pvalue <- c(".000 - .005",".005 - .010",".010 - .015",".015 - .020",".020 - .025",".025 - .030",".030 - .035",".035 - .040",".040 - .045",".045 - .050")

#Create frequency counts
count <- c(5000,4000,3100,2540,2390,2260,2150,2075,2050,2025)

dat <- data.frame(pvalue = pvalue, count = count)

#Create plot
myPlot <- ggplot(data=dat, aes(x=pvalue, y=count, group=1)) +
    geom_line() +
    geom_point() +
    geom_vline(xintercept=which(dat$pvalue == '.045 - .050'), linetype = "dashed") +
    theme_bw() +
    theme(axis.text.x = element_text(angle=90),
          panel.grid.major = element_blank(),
          panel.grid.minor = element_blank(),
          panel.background = element_blank()) +
    theme(panel.border = element_blank()) +
    ggtitle(paste("Insert Plot Title Here")) +
    labs(x = "insert x-axis title here", y = "insert y-axis title here") +
    theme(plot.title = element_text(lineheight=0.5,family = "TNR")) +
    theme(axis.line.x = element_line(color="black"),
          axis.line.y = element_line(color="black")) +
    scale_y_discrete(breaks=NULL)

myPlot

以上数据集和 R 脚本生成以下图:

Note that I do not have enough "points" to embed an image so a link to the image has been created by Stack Overflow

检查图像后发现左侧面板边框(或垂直轴)缺失。我希望左侧面板边框包含在图中。但是,我想排除左侧面板边框(或垂直轴)上的刻度线。综合起来,我想要的情节是

  1. 为 y 轴添加一条垂直线,
  2. 为 x 轴添加一条水平线,
  3. 删除沿 y 轴(垂直轴)的刻度线
  4. 移除顶部面板边框
  5. 移除右面板边框

上面的 R 脚本处理了此列表中的 #2-5。然而,我试了又试,但无法弄清楚如何处理此列表中的#1——尽管我的 R 脚本中包含以下内容:

theme(axis.line.x = element_line(color="black"),
          axis.line.y = element_line(color="black")) +

有人可以帮我生成想要的图像吗?非常感谢:)

scale_y_discrete(breaks = NULL) 打断了 y 轴,因为它解释为什么都不显示。

删除那行我们有 y axis 然后我们可以删除 tickstext:

library(ggplot2)

ggplot(data=dat, aes(x=pvalue, y=count, group=1)) +
  geom_line() +
  geom_point() +
  geom_vline(xintercept=which(dat$pvalue == '.045 - .050'), linetype = "dashed") +
  ggtitle(paste("Insert Plot Title Here")) +
  labs(x = "insert x-axis title here", y = "insert y-axis title here") +
  theme_bw() +
  theme(plot.title = element_text(lineheight=0.5,family = "TNR"),
        axis.line = element_line(),
        axis.ticks.y = element_blank(),        ## <- this line
        axis.text.y = element_blank(),         ## <- and this line
        axis.text.x = element_text(angle=90),
        panel.grid.major = element_blank(),
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        panel.border = element_blank())