+ Reply to Thread
Results 1 to 11 of 11

Thread: Mulitple plotting in gplots

  1. #1
    Points: 776, Level: 14
    Level completed: 76%, Points required for next Level: 24

    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Mulitple plotting in gplots



    "gplots" has a great function called plotmeans. I want to use this function to plot the means and CI of some grouped data (which is non-nomal) - I have done that.

    However then I would then like to plot medians and CI's generated through bootstrapping and plot them on the same axes so I have two lines with points (mean and medians) each with CI's.

    Is this possible?
    How would I code to add the plot of medians etc on top of the plotmeans line?

    Any help appreciated.

    Regards

    T

  2. #2
    Probably A Mammal
    Points: 14,462, Level: 78
    Level completed: 3%, Points required for next Level: 388
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    1,951
    Thanks
    221
    Thanked 419 Times in 387 Posts

    Re: Mulitple plotting in gplots

    You can do this with base graphics by specifying your points (medians) and using segments and feeding them the medians plus/minus the CIs you calculate. Takes a few more lines than one boxed command, but it gives you that control you desire. I've only used gplots once, so I'm not familiar with its functions.

  3. #3
    TS Contributor
    Points: 6,557, Level: 53
    Level completed: 4%, Points required for next Level: 193
    Lazar's Avatar
    Location
    Sydney
    Posts
    663
    Thanks
    109
    Thanked 164 Times in 149 Posts

    Re: Mulitple plotting in gplots

    I do not know the exact code but typically it would be something like:
    Code: 
    plot1 <- ggplot (CODE  FOR MEANS and CIs)
    plot2 <- plot1 + CODE FOR MEDIANS and CIs
    something like stat_summary(fun.y = "median", geom = "line") might be what you need and median_hilow() will give you upper and lower quatiles.

    PS the ggplot mailing list will give you exact (if not always polite) advice.

  4. #4
    RotParaTon
    Points: 46,165, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,066
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: Mulitple plotting in gplots

    At first I immediately thought of ggplot2 as well. But they seem to be asking about gplots.

  5. #5
    TS Contributor
    Points: 6,557, Level: 53
    Level completed: 4%, Points required for next Level: 193
    Lazar's Avatar
    Location
    Sydney
    Posts
    663
    Thanks
    109
    Thanked 164 Times in 149 Posts

    Re: Mulitple plotting in gplots

    oh right. Scratch that.

  6. #6
    Points: 776, Level: 14
    Level completed: 76%, Points required for next Level: 24

    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Mulitple plotting in gplots

    Hi All
    Thanks for the quick replies.
    gplots has another function "plotCI" which looks promising.
    I might try that before bryans advice.

    On another note - iof I have a function that produces a plot( ie plotmeans in gplot) how can I get, view, extract the data points providing the plot???

    Regards

    S

  7. #7
    RotParaTon
    Points: 46,165, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,066
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: Mulitple plotting in gplots

    It doesn't look like the plotmeans function has an option to return the calculated means. But it's easy enough to replicate that kind of behavior using the apply family of functions.

  8. #8
    Probably A Mammal
    Points: 14,462, Level: 78
    Level completed: 3%, Points required for next Level: 388
    bryangoodrich's Avatar
    Location
    Sacramento, California, United States
    Posts
    1,951
    Thanks
    221
    Thanked 419 Times in 387 Posts

    Re: Mulitple plotting in gplots

    I know I have an example of plotting confidence intervals on my website. Check out chapters 2 or 3 in my ALSM project. Search for "segment" and you should find the code. Segments draws exactly that, a segment based on the start and end points you give. Your goal is simply to supply the start (the median) and the end point (median+CI radius). Since you should be able to calculate the median and CIs separately, you'll have all the data to produce your plot. Just do plot followed by segments with the appropriate inputs (see help pages). It's not as nice as a one-liner, but it really is at most like 4 lines.

  9. #9
    Super Moderator
    Points: 14,605, Level: 78
    Level completed: 39%, Points required for next Level: 245
    bugman's Avatar
    Posts
    1,492
    Thanks
    88
    Thanked 140 Times in 109 Posts

    Re: Mulitple plotting in gplots

    Can't you just plot your means and create a new vector of your median values then use the add=T operator?

    plotci will do this nicely!

    Alternatively, I'd follow bryans advice and use the segments function in base.
    The earth is round: P<0.05

  10. #10
    Points: 776, Level: 14
    Level completed: 76%, Points required for next Level: 24

    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: Mulitple plotting in gplots

    Hi bugman

    If I use plotCI and want to add a another line of medians with+/- CI what form would the vector take??

  11. #11
    RotParaTon
    Points: 46,165, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,066
    Thanks
    211
    Thanked 1,605 Times in 1,375 Posts

    Re: Mulitple plotting in gplots


    You can always check the help file for plotCI
    Code: 
    ?plotCI
    alternatively to see the examples provided in the help file in action you can use the example function
    Code: 
    example(plotCI)

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats