R | ggplot2 | (删除刻度线+删除面板边框),但保持轴线

Jam*_*s F 2 r ggplot2 border-layout axis-labels yaxis

这里的新手用户,请客气和温柔!:)

我正在处理以下数据集和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
Run Code Online (Sandbox Code Playgroud)

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

请注意,我没有足够的“点”来嵌入图像,因此堆栈溢出已创建到图像的链接

对图像的检查显示,缺少左面板边框(或垂直轴)。我希望左侧面板边框包含在图中。但是,我想排除左侧面板边框(或垂直轴)上的刻度线。综上所述,我想要的情节会

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

上面的R脚本在此列表中处理#2-5。但是,尽管我的R脚本中包含以下内容,但我已经尝试了很多次,并且无法弄清楚如何处理此列表中的第一名:

theme(axis.line.x = element_line(color="black"),
          axis.line.y = element_line(color="black")) +
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我产生所需的图像吗?非常感谢 :)

GGa*_*mba 5

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()) 
Run Code Online (Sandbox Code Playgroud)