Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8600523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:38:11+00:00 2026-06-12T01:38:11+00:00

How can I generate a ggplot2 scatterplot of two groups with the means indicated

  • 0

How can I generate a ggplot2 scatterplot of two groups with the means indicated together with X and Y error bars, like this?

Scatter plot

Here is a reduced example (using dput to recreate the data.frame df) with two groups of cells and three measures, and I’d like to say plot Peak against Rise, or Peak against Decay. That much is straightforward, but I would like to add points indicating the group means with X and Y error bars (+/- sem).

Is there a way to do this within ggplot2, or do I need to generate means and sem values first? This post draw my attention to geom_errorbarh but I’m still uncertain as to the best way to proceed.

library(ggplot2)

df<-structure(list(Group = c("A", "A", "A", "A", "A", "A", "A", 
"A", "B", "B", "B", "B", "B", "B", "B", "B"), Peak = c(102.975, 
37.805, 64.996, 66.36, 199.354, 7.425, 34.137, 366.59, 10.165, 
14.833, 702.525, 39.086, 8.286, 122.783, 105.762, 37.018), Rise = c(0.346855, 
0.24165, 0.24028, 0.461548, 0.194016, 0.164047, 0.484375, 0.307861, 
0.438538, 0.488083, 0.549423, 0.365448, 0.511551, 0.33596, 0.331467, 
0.270096), Decay = c(1.3874, 1.07407, 1.88787, 2.64408, 1.1462, 
0.615963, 4.04641, 1.48701, 3.61397, 4.1838, 1.92746, 3.64329, 
4.21354, 0.812695, 1.14611, 1.28279)), .Names = c("Group", 
"Peak", "Rise", "Decay"), class = "data.frame", row.names = c(NA, 
-16L))

ggplot(df, aes(Peak, Rise)) + 
  geom_point(aes(colour=Group)) +
  theme_bw(14)

I have tried something like:

library(doBy)

sem <- function(x) sqrt(var(x)/length(x))
z<-summaryBy(Peak+Rise+Decay~Group, data=df, FUN=c(mean,sem))
z

to get the values, but easily (and flexibly) incorporating them into the ggplot code is defeating me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T01:38:12+00:00Added an answer on June 12, 2026 at 1:38 am

    I tend to use plyr for these kinds of summaries:

    z <- ddply(df,.(Group),summarise,
                Peak = mean(Peak),
                Rise = mean(Rise),
                PeakSE = sqrt(var(Peak))/length(Peak),
                RiseSE = sqrt(var(Rise))/length(Rise))
    
    ggplot(df,aes(x = Peak,y = Rise)) + 
        geom_point(aes(colour = Group)) + 
        geom_point(data = z,aes(colour = Group)) +
        geom_errorbarh(data = z,aes(xmin = Peak - PeakSE,xmax = Peak + PeakSE,y = Rise,colour = Group,height = 0.01)) + 
        geom_errorbar(data = z,aes(ymin = Rise - RiseSE,ymax = Rise + RiseSE,x = Peak,colour = Group))
    

    enter image description here

    I confess I was a little disappointed that I had to manually tweak the crossbar height. But thinking about it, I guess that could be fairly challenging to implement.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code here can generate numbers like this [1 -2 3 -4 5 -6
In C# I can generate random number from a string like this: public string
I can generate a hexbin diagram like this (code taken from http://matplotlib.org/examples/pylab_examples/hexbin_demo.html ) import
i can generate random number between two numbers in c using this.. arc4random()%(high-low+1)+low; then
I can generate a few lines of code that will do this but I'm
The program below can generate random data according to some specs (example here is
I have this table where I can generate dynamic rows (which has input <type=text
Looking for something like PyDoc that can generate a set of Wiki style pages
I'm looking for some tool that can generate many document formats like Microsoft Excel,
I found you can generate this in SOAP in php: <foo bar=blah>12345</foo> With this:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.