[R] ggplot- using geom_point and geom_line at the same time
R. Michael Weylandt <michael.weylandt@gmail.com>
michael.weylandt at gmail.com
Tue Jan 17 02:13:07 CET 2012
Just jumping into the thread it looks like your penultimate and antepenultimate lines of code both add a legend - perhaps cut one?
Michael
On Jan 16, 2012, at 7:05 PM, Mary Kindall <mary.kindall at gmail.com> wrote:
> Thanks for reply
> I wanted to have legend name with spaces. Right now I am using the
> following code but it produce two legends. I have to use Gimp to cut the
> redundant legend.
>
> ----------
> con = textConnection("inputs var1 var2 var3
> 100 10 5 2
> 1000 20 10 4
> 5000 30 15 8
> 10000 40 20 16
> 30000 50 25 32")
> data = read.table(con, header=TRUE)
> data
> data = melt(data, id="inputs")
> g <- ggplot(data,aes(x=inputs, value, colour= variable, fill = variable,
> shape=variable))
> g <- g + geom_line(lwd=0.8)
> g <- g + geom_point()
> g <- g + scale_colour_discrete('my Custom Legend')
> g <- g + scale_shape_discrete("my Custom Legend")
> g
>
> -----------------
>
> On Mon, Jan 16, 2012 at 6:55 PM, Felipe Carrillo
> <mazatlanmexico at yahoo.com>wrote:
>
>> Mary:
>> Here's one way.
>> ## change the variable name to whatever title you want on your legend
>> data = melt(data, id="inputs",variable_name="customName")
>> data
>> g <- ggplot(data,aes(x=inputs, value, colour= customName, fill =
>> customName,
>> shape=customName))
>> g <- g + geom_line(lwd=0.8)
>> g <- g + geom_point()
>> g <- g + scale_x_continuous(name='Number of inputs')
>> g <- g + scale_y_continuous('Conversion time (sec.)')
>>
>> Felipe D. Carrillo
>> Supervisory Fishery Biologist
>> Department of the Interior
>> US Fish & Wildlife Service
>> California, USA
>> http://www.fws.gov/redbluff/rbdd_jsmp.aspx
>>
>> *From:* Mary Kindall <mary.kindall at gmail.com>
>> *To:* r-help at r-project.org
>> *Sent:* Monday, January 16, 2012 1:14 PM
>> *Subject:* [R] ggplot- using geom_point and geom_line at the same time
>>
>> Hi
>> I am plotting line chart using ggplot and want to use geom_line and
>> geom_point simultaneously. I want to rename my legend but uptonow I remain
>> unsuccessful.
>> Someone please point what to add for renaming the legend.
>> I attached my example below.
>> Thanks
>>
>>
>>
>> con = textConnection("inputs var1 var2 var3
>> 100 10 5 2
>> 1000 20 10 4
>> 5000 30 15 8
>> 10000 40 20 16
>> 30000 50 25 32")
>> data = read.table(con, header=TRUE)
>> data
>> data = melt(data, id="inputs")
>> g <- ggplot(data,aes(x=inputs, value, colour= variable, fill = variable,
>> shape=variable))
>> g <- g + geom_line(lwd=0.8)
>> g <- g + geom_point()
>> g <- g + scale_x_continuous(name='Number of inputs')
>> g <- g + scale_y_continuous('Conversion time (sec.)')
>> g
>>
>>
>>
>> --
>> -------------
>> Mary Kindall
>> Yorktown Heights, NY
>> USA
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>>
>
>
> --
> -------------
> Mary Kindall
> Yorktown Heights, NY
> USA
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list