GGPLOT Question

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

GGPLOT Question

philip_rhoades
People,

I have this script:

library(ggplot2)

df <- read.table(text = " id min max
  Sp1 8.5 13.2
  Sp2 11.7 14.5
  Sp3 14.7 17.7 ", header=TRUE)

ggplot(df) +
  geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
  fill = "blue", fatten = 0)

- is there some way to get geom_crossbar to print horizontally? - I
couldn't find it . . and there doesn't seem to be a horizontal
equivalent?

Thanks,

Phil.
--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail:  [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: GGPLOT Question

ssefick
add +coord_flip() at the end. Does that do it?


On Sun, Apr 6, 2014 at 7:03 AM, Philip Rhoades <[hidden email]> wrote:

> People,
>
> I have this script:
>
> library(ggplot2)
>
> df <- read.table(text = " id min max
>  Sp1 8.5 13.2
>  Sp2 11.7 14.5
>  Sp3 14.7 17.7 ", header=TRUE)
>
> ggplot(df) +
>  geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
>  fill = "blue", fatten = 0)
>
> - is there some way to get geom_crossbar to print horizontally? - I
> couldn't find it . . and there doesn't seem to be a horizontal equivalent?
>
> Thanks,
>
> Phil.
> --
> Philip Rhoades
>
> GPO Box 3411
> Sydney NSW      2001
> Australia
> E-mail:  [hidden email]
>
> ______________________________________________
> [hidden email] 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.
>



--
Stephen Sefick
**************************************************
Auburn University
Biological Sciences
331 Funchess Hall
Auburn, Alabama
36849
**************************************************
[hidden email]
http://www.auburn.edu/~sas0025
**************************************************

Let's not spend our time and resources thinking about things that are so
little or so large that all they really do for us is puff us up and make us
feel like gods.  We are mammals, and have not exhausted the annoying little
problems of being mammals.

                                -K. Mullis

"A big computer, a complex algorithm and a long time does not equal
science."

                              -Robert Gentleman

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: GGPLOT Question

philip_rhoades
Stephen,


On 2014-04-06 22:09, stephen sefick wrote:
> add +coord_flip() at the end. Does that do it?


Wow! - that was a fast response! - yes that works - thanks a lot!

Regards,

Phil.


> On Sun, Apr 6, 2014 at 7:03 AM, Philip Rhoades <[hidden email]>
> wrote:
>
>> People,
>>
>> I have this script:
>>
>> library(ggplot2)
>>
>> df <- read.table(text = " id min max
>>  Sp1 8.5 13.2
>>  Sp2 11.7 14.5
>>  Sp3 14.7 17.7 ", header=TRUE)
>>
>> ggplot(df) +
>>  geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
>>  fill = "blue", fatten = 0)
>>
>> - is there some way to get geom_crossbar to print horizontally? - I
>> couldn't find it . . and there doesn't seem to be a horizontal
>> equivalent?
>>
>> Thanks,
>>
>> Phil.
>> --
>> Philip Rhoades
>>
>> GPO Box 3411
>> Sydney NSW      2001
>> Australia
>> E-mail:  [hidden email]
>>
>> ______________________________________________
>> [hidden email] 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.
>>
>
>
>
> --
> Stephen Sefick
> **************************************************
> Auburn University
> Biological Sciences
> 331 Funchess Hall
> Auburn, Alabama
> 36849
> **************************************************
> [hidden email]
> http://www.auburn.edu/~sas0025
> **************************************************
>
> Let's not spend our time and resources thinking about things that are
> so
> little or so large that all they really do for us is puff us up and
> make us
> feel like gods.  We are mammals, and have not exhausted the annoying
> little
> problems of being mammals.
>
>                                 -K. Mullis
>
> "A big computer, a complex algorithm and a long time does not equal
> science."
>
>                               -Robert Gentleman
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail:  [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: GGPLOT Question - #2

philip_rhoades
People,

OK, the last two bits of the puzzle - can I colour the bars
independently and change the scale from linear to logarithmic?

Thanks,

Phil.


On 2014-04-06 22:23, Philip Rhoades wrote:

> Stephen,
>
>
> On 2014-04-06 22:09, stephen sefick wrote:
>> add +coord_flip() at the end. Does that do it?
>
>
> Wow! - that was a fast response! - yes that works - thanks a lot!
>
> Regards,
>
> Phil.
>
>
>> On Sun, Apr 6, 2014 at 7:03 AM, Philip Rhoades <[hidden email]>
>> wrote:
>>
>>> People,
>>>
>>> I have this script:
>>>
>>> library(ggplot2)
>>>
>>> df <- read.table(text = " id min max
>>>  Sp1 8.5 13.2
>>>  Sp2 11.7 14.5
>>>  Sp3 14.7 17.7 ", header=TRUE)
>>>
>>> ggplot(df) +
>>>  geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
>>>  fill = "blue", fatten = 0)
>>>
>>> - is there some way to get geom_crossbar to print horizontally? - I
>>> couldn't find it . . and there doesn't seem to be a horizontal
>>> equivalent?
>>>
>>> Thanks,
>>>
>>> Phil.
>>> --
>>> Philip Rhoades
>>>
>>> GPO Box 3411
>>> Sydney NSW      2001
>>> Australia
>>> E-mail:  [hidden email]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>>
>>
>>
>>
>> --
>> Stephen Sefick
>> **************************************************
>> Auburn University
>> Biological Sciences
>> 331 Funchess Hall
>> Auburn, Alabama
>> 36849
>> **************************************************
>> [hidden email]
>> http://www.auburn.edu/~sas0025
>> **************************************************
>>
>> Let's not spend our time and resources thinking about things that are
>> so
>> little or so large that all they really do for us is puff us up and
>> make us
>> feel like gods.  We are mammals, and have not exhausted the annoying
>> little
>> problems of being mammals.
>>
>>                                 -K. Mullis
>>
>> "A big computer, a complex algorithm and a long time does not equal
>> science."
>>
>>                               -Robert Gentleman
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.

--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail:  [hidden email]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: GGPLOT Question - #2

philip_rhoades
People,


On 2014-04-06 22:31, Philip Rhoades wrote:
> People,
>
> OK, the last two bits of the puzzle - can I colour the bars
> independently and change the scale from linear to logarithmic?


To answer my own question - the attached file works for me but I guess
could be improved?

Thanks,

Phil.



> On 2014-04-06 22:23, Philip Rhoades wrote:
>> Stephen,
>>
>>
>> On 2014-04-06 22:09, stephen sefick wrote:
>>> add +coord_flip() at the end. Does that do it?
>>
>>
>> Wow! - that was a fast response! - yes that works - thanks a lot!
>>
>> Regards,
>>
>> Phil.
>>
>>
>>> On Sun, Apr 6, 2014 at 7:03 AM, Philip Rhoades <[hidden email]>
>>> wrote:
>>>
>>>> People,
>>>>
>>>> I have this script:
>>>>
>>>> library(ggplot2)
>>>>
>>>> df <- read.table(text = " id min max
>>>>  Sp1 8.5 13.2
>>>>  Sp2 11.7 14.5
>>>>  Sp3 14.7 17.7 ", header=TRUE)
>>>>
>>>> ggplot(df) +
>>>>  geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
>>>>  fill = "blue", fatten = 0)
>>>>
>>>> - is there some way to get geom_crossbar to print horizontally? - I
>>>> couldn't find it . . and there doesn't seem to be a horizontal
>>>> equivalent?
>>>>
>>>> Thanks,
>>>>
>>>> Phil.
>>>> --
>>>> Philip Rhoades
>>>>
>>>> GPO Box 3411
>>>> Sydney NSW      2001
>>>> Australia
>>>> E-mail:  [hidden email]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>>>>
>>>
>>>
>>>
>>> --
>>> Stephen Sefick
>>> **************************************************
>>> Auburn University
>>> Biological Sciences
>>> 331 Funchess Hall
>>> Auburn, Alabama
>>> 36849
>>> **************************************************
>>> [hidden email]
>>> http://www.auburn.edu/~sas0025
>>> **************************************************
>>>
>>> Let's not spend our time and resources thinking about things that are
>>> so
>>> little or so large that all they really do for us is puff us up and
>>> make us
>>> feel like gods.  We are mammals, and have not exhausted the annoying
>>> little
>>> problems of being mammals.
>>>
>>>                                 -K. Mullis
>>>
>>> "A big computer, a complex algorithm and a long time does not equal
>>> science."
>>>
>>>                               -Robert Gentleman
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
--
Philip Rhoades

GPO Box 3411
Sydney NSW 2001
Australia
E-mail:  [hidden email]
______________________________________________
[hidden email] 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.

TechComparison.r (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GGPLOT Question - #2

YRichard
Hi Phil,
You don't need multiple data frames. A single one will do. Try that.

df <- rbind(df1, df2, df3, df4, df5, df6)
df$type <- c('a','a','b','b','c','c')
ggplot() +
    geom_crossbar(data = df, aes(ymin=min, ymax=max, x=Treatment,
y=min, fill=type, fatten=0)) +
    scale_fill_manual(values=c(a='red', b='orange', c='green'), guid='none') +
    ylab( "Days" ) +
    scale_y_log10( breaks=c( 0.01, 0.1, 1.0, 10.0, 100.1, 1000.0,
10000.0, 100000.0 ), labels=c( "0.01", "0.1", "1.0", "10", "100",
"1,000", "10,000", "100,000" ) ) +
    coord_flip() +
    ggtitle( "Comparison of Medical Temperature Reduction Treatments" )


On 7 April 2014 03:38, Philip Rhoades <[hidden email]> wrote:

> People,
>
>
>
> On 2014-04-06 22:31, Philip Rhoades wrote:
>>
>> People,
>>
>> OK, the last two bits of the puzzle - can I colour the bars
>> independently and change the scale from linear to logarithmic?
>
>
>
> To answer my own question - the attached file works for me but I guess could
> be improved?
>
>
> Thanks,
>
> Phil.
>
>
>
>> On 2014-04-06 22:23, Philip Rhoades wrote:
>>>
>>> Stephen,
>>>
>>>
>>> On 2014-04-06 22:09, stephen sefick wrote:
>>>>
>>>> add +coord_flip() at the end. Does that do it?
>>>
>>>
>>>
>>> Wow! - that was a fast response! - yes that works - thanks a lot!
>>>
>>> Regards,
>>>
>>> Phil.
>>>
>>>
>>>> On Sun, Apr 6, 2014 at 7:03 AM, Philip Rhoades <[hidden email]>
>>>> wrote:
>>>>
>>>>> People,
>>>>>
>>>>> I have this script:
>>>>>
>>>>> library(ggplot2)
>>>>>
>>>>> df <- read.table(text = " id min max
>>>>>  Sp1 8.5 13.2
>>>>>  Sp2 11.7 14.5
>>>>>  Sp3 14.7 17.7 ", header=TRUE)
>>>>>
>>>>> ggplot(df) +
>>>>>  geom_crossbar(aes(ymin = min, ymax = max, x = id, y = min),
>>>>>  fill = "blue", fatten = 0)
>>>>>
>>>>> - is there some way to get geom_crossbar to print horizontally? - I
>>>>> couldn't find it . . and there doesn't seem to be a horizontal
>>>>> equivalent?
>>>>>
>>>>> Thanks,
>>>>>
>>>>> Phil.
>>>>> --
>>>>> Philip Rhoades
>>>>>
>>>>> GPO Box 3411
>>>>> Sydney NSW      2001
>>>>> Australia
>>>>> E-mail:  [hidden email]
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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.
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Stephen Sefick
>>>> **************************************************
>>>> Auburn University
>>>> Biological Sciences
>>>> 331 Funchess Hall
>>>> Auburn, Alabama
>>>> 36849
>>>> **************************************************
>>>> [hidden email]
>>>> http://www.auburn.edu/~sas0025
>>>> **************************************************
>>>>
>>>> Let's not spend our time and resources thinking about things that are so
>>>> little or so large that all they really do for us is puff us up and make
>>>> us
>>>> feel like gods.  We are mammals, and have not exhausted the annoying
>>>> little
>>>> problems of being mammals.
>>>>
>>>>                                 -K. Mullis
>>>>
>>>> "A big computer, a complex algorithm and a long time does not equal
>>>> science."
>>>>
>>>>                               -Robert Gentleman
>>>>
>>>>         [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>
>
> --
> Philip Rhoades
>
> GPO Box 3411
> Sydney NSW      2001
> Australia
> E-mail:  [hidden email]
>
> ______________________________________________
> [hidden email] 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.
>



--
Yvan Richard

      DRAGONFLY Science

Physical address: Level 5, 158 Victoria St, Te Aro, Wellington
Postal address: PO Box 27535, Wellington 6141
New Zealand
Ph: 04.385.9285
web page

______________________________________________
[hidden email] 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.