Displaying 20 results from an estimated 10000 matches similar to: "ggplot2: positioning legend on top of plot"
2008 Aug 14
1
ggplot2: remove minor-horizontal guide before drawing
Hi,
I want to remove minor-horizontal and minor-vertical lines from a plot
generated with ggplot2. I can do this after the plot has been drawn
using grid.gremove.
However, I would like to do it before drawing my plot. The ggplot2 book
refers to a ggplotGrob function which creates a grob from a plot but
this function doesn't seem to exist in ggplot2 0.6.
Is there another way to do it?
2009 May 16
1
ggplot2: annotating plot with mathematical formulae
Hi,
Is there a way of annotating a ggplot plot with mathematical formulae?
I can do
geom_text(aes(label="some text", ...
but I can't do
geom_text(aes(label=expression(x^{n-1}), ...
It gives the error
Error: geom_text requires the following missing aesthetics: label
Is there a convenient equivalent?
Cheers,
Paul
2009 May 10
1
ggplot2: recommended workaround for broken legend.position="top"
Searching the mail archives I found that using legend.position as in
p.ring.3 + opts(legend.position="top")
is a known bug. I tried doing
p.ring.3 + opts(legend.position=c(0.8, 0.2))
which works, but the legend background is transparent, i.e. I see the
plot background through the legend. Adding additional option
opts(legend.background=theme_rect(fill=TRUE,colour="white"))
2010 Jun 07
1
Patch for legend.position={left,top,bottom} in ggplot2
Hi Hadley and everyone,
here's a patch for ggplot2 that fixes the behavior of
opts(legend.position={left,top,bottom}). If you try the following code
in an unmodified ggplot2
options(warn = -1)
suppressPackageStartupMessages(library("ggplot2"))
data <- data.frame(
x = c(1, 2, 3, 4, 5, 6),
y = c(2, 3, 4, 3, 4, 5),
colour = c(TRUE, TRUE, TRUE, FALSE, FALSE, FALSE))
2009 Jan 30
1
Using ggplot2 I need to move the location of legend to on the plot
Thanks again for the hints about adding the vertical line to the hist plot and in ggplot. That worked great.
Based on that advice I've been flipping through the ggplot2 doc and ggplot-static\index.html webpage more looking for the answer to the next question.
Unfortunately, I haven't stumbled on a description of how to move around the location of the legend.
Here is what I
2009 Aug 19
2
ggplot2 legend problem
I'm trying to overlay two histograms using transparency to enable viewing of
multiple distributions on a single scale. So far ggplot2 seems to do what I
want. However I'm having a problem generating the legend coloring
appropriate to each distribution in the plot.
Here is a test case to show my best (failed) effort so far:
library(ggplot2)
x <- data.frame(X=rnorm(1000, mean=0))
y
2010 Mar 24
1
GGPLOT2: Reverse order of legend to match order of x-axis
How do I reverse the order of the legend in a bar plot to match order of the
x-axis? In other words, I want the stacked colors of the legend to match the
stacked colors of the bar plot. I tried this, but it didn't work.
colors <- c("5" = "red","4" = "blue","3" = "darkgreen")
p <- qplot(factor(cyl), data=mtcars,
2007 Sep 03
1
Legend issue with ggplot2
Dear useRs,
I'm struggling with the new version of ggplot2. In the previous version
I did something like this. But now this yield an error (object "fill"
not found).
library(ggplot2)
dummy <- data.frame(x = rep(1:10, 4), group = gl(4, 10))
dummy$y <- dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group]
dummy$min <- dummy$y - 5
dummy$max <- dummy$y + 5
ggplot(data
2009 Mar 20
1
ggplot2: specifying legend titles
I am trying to specify a legend title to be other than the variable
name, but I find that the legend splits because scale_shape() takes
effect but scale_colour() does not. Can someone spot my error?
Here's some toy code that produces the problem on my system (R2.8.1,
windows, today's CRAN package updates):
library(ggplot2)
a <- sample(letters[1:5],100,replace=T)
b <-
2011 Aug 29
1
Legend / bar order - ggplot2
Hi all,
I am trying to do a barplot in ggplot2 and want to make sure that the legend order is consistent with the bar order, that is the legend order is orig and match; and the bars are ordered in the same way. It seems to me that I can only control one of them. Any idea?
library(ggplot2)
df <- data.frame(value = rnorm(20),
name = factor(rep(letters[1:10], 2), levels =
2010 Feb 08
1
R ggplot2 legend text left justify
In ggplot2 how do you justify the legend text ?
In the example below the opts(legend.text = theme_text(size =
9,hjust=0)) changes the size of the text OK but it remains right
justified.
> mydata=data.frame(RowID=c("A","B","C"),Name=c("long long long long
long name","short name ","medium medium name"),Speed=c(100,140,120))
>
2008 Jul 03
1
ggplot2 legend for vertical lines
Dear all,
The following example code produces a graph with ggplot2, to which I
add several vertical lines of arbitrary colors. I am not satisfied
with the legend: it automatically adds some vertical lines which I'd
rather not see (they confuse the reader rather than add information
in this case).
> library(ggplot2)
> dfr <- data.frame(values = sin(1:50/10),
> fact =
2012 Aug 10
1
ggplot2 geom_bar produces white slashes in legend keys
When I am using geom_bar I get these white slashes through the legend keys. I cannot figure out how to remove them.
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()
I have tried using opts(legend.key = theme_blank()) but with no luck.
Any suggestions would be much appreciated.
I am using R vers. 2.15.0 and ggplot 0.9.1, win xp
Best wishes
Jonas Hal
2008 Apr 12
1
ggplot2 - plot with only legend?
I just found out that this message got scrambled with other threads,
so I trying to re-send...
Dear R'ers,
I am trying to build a composite plot (with several plots in one
figure). I have tried, but I cannot use facetting, as I need to
customize each plot using grid.
Since all the plots are the same (with different data, but same
layout and categories), I would like to have only one legend,
2010 Apr 30
0
ggplot2 legend how?
Hello,
I have just ordered the "ggplot2: Elegant Graphics for Data Analysis (Use R)" but while it arrives :) can anyone please show me how to setup and add a simple legend to a ggplot?
This is my use case, I need a legend showing CI "Classic", "Own bootstrap", "R bootstrap":
library(ggplot2)
e <- 1
p <- 1
x <- 1:S
y <- rep(betas[p],S)
data
2017 Oct 01
0
Adding non-data line to legend ggplot2 Maximum Contaminant Level
I just glanced at the problem but I think you would have to create a new variable to replace the hline. What about adding some text annotation in the graph instead?
On Tuesday, September 26, 2017, 3:51:46 PM EDT, David Doyle <kydaviddoyle at gmail.com> wrote:
Hello everyone,
I have a plot showing chloride concentrations for various point over time.
I also have a dotted line that
2017 Sep 26
2
Adding non-data line to legend ggplot2 Maximum Contaminant Level
Hello everyone,
I have a plot showing chloride concentrations for various point over time.
I also have a dotted line that show the Secondary Maximum Contaminant Level
(my screening limit) on the graphs at 250 mg/L. But I can not figure out
how to include the dotted line / Secondary Maximum Contaminant Level in
the legend. Any thoughts? My code is as following and is linked to my
data on the
2009 Sep 14
1
ggplot2 legend text....a basic question
Hello fellow R's,
I?ve been learning to use the ggplot2 library, and after a full day of
work I still have a couple of basic questions.
Here is an example:
mydata=data.frame(x=runif(20),y=runif(20),n=runif(20))
mydata2=data.frame(x=c(0.4,0.6,0.5),y=c(0.4,0.4,0.6))
ggplot(mydata, aes(x, y)) + geom_point(aes(size = n)) +
geom_polygon(data=mydata2,aes(x,y,alpha=0.5))
In this plot, the
2008 Jun 16
1
ggplot2: How to remove legend component for geom_errorbar() ?
Dear list (probably Hadley),
I'm trying to do a plot like the following, composed of bars and error
bars:
df <- data.frame(factor1=gl(2,5), factor2=gl(5,1), y=rnorm(10),
err=0.1)
ggplot(df, aes(x=factor1, y=y, fill=factor2)) +
geom_bar(position="dodge", stat="identity") +
geom_errorbar(aes(min=y-err, max=y+err), position="dodge",
width=0.1)
The
2013 Sep 26
1
Less than equal to symbol in ggplot2 legend text
Hello,
I am trying to add a less than equal to symbol in a ggplot2 legend text.
See sample code below. I have tried using the expression function and
\u2264. I also tried adding labels to legend.text under theme.
Neither of these 3 options work.
Please help,
Mahesh
++++++++++++++
Extra.column=ifelse(data[,covariate]>cutpoint,1,0)
Grp1 <- "\u2264 1.5"
Grp2 <-