All Questions
1,758
questions
376
votes
4
answers
604k
views
Remove legend ggplot 2.2
I'm trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried shutting off the legends with guides(colour = FALSE) and geom_point(aes(color = vs), show....
212
votes
9
answers
271k
views
Add a common Legend for combined ggplots
I have two ggplots which I align horizontally with grid.arrange. I have looked through a lot of forum posts, but everything I try seem to be commands that are now updated and named something else.
...
200
votes
8
answers
73k
views
Remove 'a' from legend when using aesthetics and geom_text
How can I can remove the letter 'a' from the legend generated by this code? If I remove the geom_text, then the 'a' letter will not show in the legend. I want to keep geom_text, though.
ggplot(data = ...
187
votes
9
answers
194k
views
Is there a way to change the spacing between legend items in ggplot2?
Is there a way to change the spacing between legend items in ggplot2? I currently have
legend.position ="top"
which automatically produces a horizontal legend. However, the spacing of the items is ...
184
votes
4
answers
406k
views
Add legend to ggplot2 line plot
I have a question about legends in ggplot2. I managed to plot three lines in the same graph and want to add a legend with the three colors used. This is the code used
library(ggplot2)
## edit from ...
133
votes
4
answers
151k
views
Remove extra legends in ggplot2
I have a simple data frame that I'm trying to do a combined line and point plot using ggplot2. Supposing my data looks like this:
df <- data.frame(x=rep(1:10,2), y=c(1:10,11:20),
...
130
votes
4
answers
56k
views
Keep unused levels in bar plot
I want to plot unused levels (that is, levels where the count is 0) in my bar-plot, however, unused levels are dropped and I cannot figure out how to keep them
df <- data.frame(type=c("A", "A", "A"...
123
votes
2
answers
145k
views
Legend on bottom, two rows wrapped in ggplot2 in r
library(ggplot2)
library(scales)
library(reshape2)
Rdates <- c("2007-01-31","2007-02-28","2007-03-30","2007-04-30","2007-05-31","2007-06-29&...
116
votes
10
answers
164k
views
Plot labels at ends of lines
I have the following data (temp.dat see end note for full data)
Year State Capex
1 2003 VIC 5.356415
2 2004 VIC 5.765232
3 2005 VIC 5.247276
4 2006 VIC 5.579882
5 2007 VIC ...
114
votes
4
answers
150k
views
How to move or position a legend in ggplot2
I'm trying to create a ggplot2 plot with the legend beneath the plot.
The ggplot2 book says on p 112 "The position and justification of legends are controlled by the theme setting legend.position, ...
79
votes
1
answer
39k
views
Control ggplot2 legend look without affecting the plot
I'm plotting lines with ggplot2 like this:
ggplot(iris, aes(Petal.Width,Petal.Length,color=Species)) + geom_line() + theme_bw()
.
I find legend marks to be small so I want them to be bigger. If I ...
68
votes
1
answer
49k
views
R ggplot2 legend inside the figure
So, I have the following data.frame, and I want to generate two plots in one graph for yval vs. xval, for each zval and type tp. The lef
> df
xval yval se zval cond
1 1.0 ...
65
votes
6
answers
75k
views
How can I remove the legend title in ggplot2?
I have a question concerning the legend in ggplot2.
Say I have a hypothetical dataset about mean carrot length for two different colours at two farms:
carrots<-NULL
carrots$Farm<-rep(c("X","Y")...
58
votes
1
answer
47k
views
ggplot2 legend items in a single horizontal row
It seems that the code I wrote and tested last week has now suddenly decided to change the output even though nothing in the code or the version of R or Rstudio has changed.
Previously when I drew a ...
52
votes
2
answers
56k
views
change both legend titles in a ggplot with two legends
I have two legends on my ggplot with two different legend titles (automatically created from ggplot()). Now, I want to change this legend titles. + labs(colour = "legend name") only change the second ...