Remove lines from color and fill legends
You may set linetype = 0
or "blank"
(on different linetype
s here) for the fill
and color
guide
s in your override.aes
call.
Also note that I moved the fill
aes
from the 'top level' in ggplot
to geom_bar
.
ggplot(df, aes(x, y)) +
geom_bar(aes(fill = con), stat = 'identity') +
geom_point(aes(color = col)) +
geom_hline(data = hline_df, aes(yintercept = y, linetype = name), color = 'red', show_guide = TRUE) +
guides(fill = guide_legend(override.aes = list(linetype = 0)),
color = guide_legend(override.aes = list(linetype = 0)))
Remove line in legend
Based on this answer, you can override the linetype also.
Remove lines from color and fill legends
So add linetype=c(1,1,NA)
to the override.aes
list. In other words change your:
guides(color = guide_legend(override.aes = list(shape = c(NA,NA,16))))
to:
guides(color = guide_legend(override.aes = list(shape = c(NA,NA,16), linetype=c(1,1,NA))))
Removing lines within filled.contour legend
If you examine the code for filled.contour
you'll see this line:
rect(0, levels[-length(levels)], 1, levels[-1L], col = col)
that draws the color key rectangle. It's vectorized, so it's drawing each of the individual color boxes. The function rect
accepts an argument border
, which if you set to NA
will omit the internal borders of the rectangles. So create your own version of the function and change this line to :
rect(0, levels[-length(levels)], 1, levels[-1L], col = col, border = NA)
or make it an argument, rather than hard coding. When I do this, I get the following graph:
removing part of a fill legend in ggplot
Remember you can set the breaks
on any scale, so just set a single break at "daily"
on your fill scale. To merge it with the color scale (if I understand your meaning) you can just give the color guide and its single break the same names as the fill guide and fill break:
ggplot(data=df1) +
geom_rect(data = df2,
aes(xmin = x1,
xmax = x2,
ymin = 0,
ymax = Inf,
fill = color2),
color = "black",
size = 0.3,
alpha = 0.2)+
geom_bar(aes(x = x,
y= y1,
fill = "daily"),
stat='identity',
width = 0.75,
size = 0.1,
alpha = 0.5) +
geom_line(aes(x = x,
y =y2,
color = "somthing"),
size = 1.5) +
scale_fill_discrete(breaks = "daily", name = NULL) +
scale_color_discrete(name = "labels") +
theme(legend.margin = margin(0, 0, -10, 0))
Remove the line and the background in the two legends
you can try this with little modification from your code and help from @Henrik
ggplot(sal,aes(x=id,y=val,fill=id))+
geom_bar(stat="identity",position="dodge",width=.75) +
scale_fill_brewer(palette='Set1',type='qual',name='Time')+
theme(axis.title.x=element_blank(),
axis.title.y=element_blank(),
panel.background=element_rect(fill="transparent",colour=NA),
panel.grid.minor=element_line(colour='grey',linetype=2),
panel.grid.major=element_line(colour='grey'),
plot.background=element_rect(fill="transparent",colour=NA),
axis.ticks=element_blank(),
axis.text.x=element_blank(),
legend.position='bottom')+
facet_grid(.~x)+theme(strip.background=element_rect(colour='white',fill='transparent'), strip.text.x=element_text(size=15,face='bold'))+
geom_hline(aes(yintercept=lim1,lty='lim1'),lwd=0,show_guide=T)+
geom_hline(aes(yintercept=lim2,lty='lim2'),lwd=0,show.guide=T)+
geom_hline(aes(yintercept=lim1,lty='lim1'),lwd=1,show_guide=T)+
geom_hline(aes(yintercept=lim2,lty='lim2'),lwd=1,show.guide=F)+
scale_linetype_manual(name="Recommendations",values=c(3,1), labels=c('R1','R2'))+
theme(legend.key = element_rect(fill = "transparent"))+
guides(fill = guide_legend(override.aes = list(linetype = 0)), color = guide_legend(override.aes = list(linetype = 0)))
#
Removing lines on legend with geom_polygon in ggplot2 r
Can't test without data, but try this:
# Not tested...
ggplot(outputData, aes(long,lat, group = group)) +
geom_polygon(aes(fill = meanadjsmr)) +
geom_path() +
labs(x=" ", y=" ") +
scale_fill_manual(name = "", values = cust_brewer) +
theme(legend.text = element_text(size = 12))
You're getting lines on the legend because of color=black
. You can get the borders using geom_path(...)
instead.
how to remove line from fill scale legend using geom_vline and geom_histogram r ggplot2
One workaround is to change the order of geom_histogram()
and geom_vline()
. Then add another geom_vline()
without aes()
, just giving xintercept=
and linetype=
. This will not remove lines but will hide them under the color legend entries.
ggplot(data=df1, aes(x=rating, fill=cond)) +
geom_vline(data=df2,aes(xintercept=x,linetype=factor(cond)),
show_guide=TRUE) +
geom_histogram(binwidth=.5, position="dodge") +
geom_vline(xintercep=df2$x,linetype=c(1,3))+
labs(fill='Stochastic',linetype='Deterministic')
Removing borders and color from small legend boxes in ggplot2
You can use show.legend = FALSE
where you want one geom-legend not to show up.
library(ggplot2)
ggplot(my_df, aes(x = x, y = y))+
geom_point(aes(color="Daily values"))+
geom_line(aes( x = x, y = mp2, color = "High risk area"),size=1, show.legend = T)+
geom_line(aes(x = x, y = mp1, color = "Low risk area"),size=1, show.legend = F)+
geom_ribbon(data = my_df, aes(ymin=l2, ymax=u2, color="95% CI"), alpha=0.3, show.legend = F)+
geom_ribbon(data = my_df, aes(ymin=l1, ymax=u1, color="95% CI"), alpha=0.3, show.legend = F)+
scale_color_manual(values=c("gray60","darkblue","darkgreen","black"))+
ylab("My outcome")+
guides( color = guide_legend(title="My Pred Trend",
override.aes = list(linetype = c(0,1,1,1)),
shape=c(1,NA,NA,NA),
reverse=T))+
ggtitle("My Trend for this Area ")+
theme(legend.key = element_rect(fill = "white"))
How can I remove the line aesthetic from a ggplot2 legend?
All you need to do is add show.legend = FALSE
to stat_smooth
:
ggplot(df, aes(x = x, y = y, color = group, group = 1)) +
geom_smooth(method = "lm", se = FALSE, show.legend = FALSE) +
geom_point() +
theme_bw()
Related Topics
Configuration Failed Because Libcurl Was Not Found
Convert Hours:Minutes:Seconds to Minutes
How to Handle Vectors Without Knowing the Type in Rcpp
Finding Where Two Linear Fits Intersect in R
How to Access Dimensions of Labels Plotted by 'Geom_Text' in 'Ggplot2'
Ggpairs Plot with Heatmap of Correlation Values
Showing Equation of Nls Model with Ggpmisc
"Adding Missing Grouping Variables" Message in Dplyr in R
Coloring Boxplot Outlier Points in Ggplot2
Why Is Subsetting on a "Logical" Type Slower Than Subsetting on "Numeric" Type
Add an Image to a Table-Like Output in R
Add Axis Tick-Marks on Top and to the Right to a Ggplot
R Shiny, How to Make Datatable React to Checkboxes in Datatable