本文介绍了我怎样才能抑制ggplot2图中的垂直网格线?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在构建一个条形图,该条形图足以作为水平(x)布局的指示,所以我想避免绘制多余的垂直网格线。我知道如何设计opts()中的小网格线和主网格线,但我无法想象如何抑制垂直网格线。 data ggplot(data,aes(x,y))+ geom_bar(stat ='identity')+ opts( panel.grid.major = theme_line(size = 0.5,color ='#1391FF'), panel.grid.minor = theme_line(color = NA), panel.background = theme_rect(颜色= NA), axis.ticks = theme_segment(color = NA)) 在这一点上,看起来我将不得不压制所有的网格线,然后用geom_hline()将它们拉回来,这看起来像是一种痛苦(也不是完全清楚我如何找到tick /主要的网格线位置以提供给geom_hline()。) 任何想法都不胜感激! scale_x_continuous(breaks = NULL)解决方案 这将删除所有垂直网格线和x轴tickmark标签。 I am building a bar chart for which bars suffice as indications of horizontal (x) placement, so I'd like to avoid drawing the superfluous vertical gridlines.I understand how to style the minor and major gridlines in opts(), but I can't for the life of me figure out how to suppress just the vertical gridlines.library(ggplot2)data <- data.frame(x = 1:10, y = c(3,5,2,5,6,2,7,6,5,4))ggplot(data, aes(x, y)) + geom_bar(stat = 'identity') + opts( panel.grid.major = theme_line(size = 0.5, colour = '#1391FF'), panel.grid.minor = theme_line(colour = NA), panel.background = theme_rect(colour = NA), axis.ticks = theme_segment(colour = NA) )At this point, it's looking like I'm going to have to suppress all of the gridlines and then draw them back in with geom_hline(), which seems like kind of a pain (also, it's not entirely clear how I can find the tick/major gridline positions to feed to geom_hline().)Any thoughts would be appreciated! 解决方案 Try using scale_x_continuous(breaks = NULL)This would remove all the vertical gridlines as well as x-axis tickmark labels. 这篇关于我怎样才能抑制ggplot2图中的垂直网格线?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 06-05 20:42