簡體   English   中英

如何從圖例中刪除邊框而不從ggplot2中的條形圖中刪除邊框

[英]How to remove borders from the legend without removing borders from the bar plot in ggplot2

我有以下情節:

library(reshape)
library(ggplot2)
library(gridExtra)
require(ggplot2)



data2<-structure(list(IR = structure(c(4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L
), .Label = c("0.13-0.16", "0.17-0.23", "0.24-0.27", "0.28-1"
), class = "factor"), variable = structure(c(1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L), .Label = c("Real queens", "Simulated individuals"
), class = "factor"), value = c(15L, 11L, 29L, 42L, 0L, 5L, 21L, 
22L), Legend = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("Real queens", 
"Simulated individuals"), class = "factor")), .Names = c("IR", 
"variable", "value", "Legend"), row.names = c(NA, -8L), class = "data.frame")
p <- ggplot(data2, aes(x =factor(IR), y = value, fill = Legend, width=.15))


data3<-structure(list(IR = structure(c(4L, 3L, 2L, 1L, 4L, 3L, 2L, 1L
), .Label = c("0.13-0.16", "0.17-0.23", "0.24-0.27", "0.28-1"
), class = "factor"), variable = structure(c(1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L), .Label = c("Real queens", "Simulated individuals"
), class = "factor"), value = c(2L, 2L, 6L, 10L, 0L, 1L, 4L, 
4L), Legend = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L), .Label = c("Real queens", 
"Simulated individuals"), class = "factor")), .Names = c("IR", 
"variable", "value", "Legend"), row.names = c(NA, -8L), class = "data.frame")
q<- ggplot(data3, aes(x =factor(IR), y = value, fill = Legend, width=.15))


##the plot##
q + geom_bar(position='dodge', colour='black') + ylab('Frequency') + 
        xlab('IR')+scale_fill_grey() +
        theme(axis.text.x=element_text(colour="black"), 
        axis.text.y=element_text(colour="Black"))+ 
        opts(title='', panel.grid.major = theme_blank(),panel.grid.minor = 
        theme_blank(),panel.border = theme_blank(),panel.background = 
        theme_blank(), axis.ticks.x = theme_blank())

我想保持黑色邊框效果

geom_bar(colour='black)

而在圖例中所描繪的方塊上沒有怪異的斜線。 有什么辦法可以使它們解耦或刪除對角線嗎?

作為Didzis Elferts提到的,有這樣的例子在這里 (最后一個例子)。

訣竅是要疊加兩個圖:第一個圖以所需的方式處理圖例,第二個圖沒有圖例,但為實際圖本身添加了邊框。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM