5

新手用户,请善待和温柔!:)

我正在处理以下数据集和 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 脚本生成以下图:

请注意,我没有足够的“点”来嵌入图像,因此 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")) +

有人可以帮我制作所需的图像吗?非常感谢 :)

4

1 回答 1

12

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

删除我们拥有的那一行,y axis然后我们可以删除ticksand text

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()) 

于 2017-07-12T14:44:00.830 回答