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 853811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:49:19+00:00 2026-05-15T07:49:19+00:00

I’m trying to understand how to have more than one series on a plot,

  • 0

I’m trying to understand how to have more than one series on a plot, using the following data.

Year <- c('1950', '1960', '1970', '1980')
Bus <- c(10,20,30,40)
Bus.sd <- c(1.1, 2.2, 3.3, 4.4)
Car <- c(20, 20, 40, 40)
Car.sd <- c(1.1, 2.2, 3.3, 4.4)

sample_data = data.frame(Year, Bus, Bus.sd, Car, Car.sd)

qplot(Year, Bus, data=sample_data, geom="pointrange", 
ymin = Bus - Bus.sd/2, ymax = Bus + Bus.sd/2)

For example, using the above data, how do I show both sample_data$Bus and sample_data$Car on the same plot in different colors?

What I tried doing was:

p <- qplot(...)

then

p <- p + qplot(...) 

where I replicated the previous line, but this gave me an error.

I don’t fully understand how AES works. I have studied the ggplot2 examples, but have difficulty understanding the relevant examples here. Or, if it is possible to make a stacked bar (geom_bar) using this data, I think that would also represent it appropriately.

  • 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-05-15T07:49:20+00:00Added an answer on May 15, 2026 at 7:49 am

    I Hope this helps

    gplot2 works best with data in long format, like so:

      Year score  sd variable
    1 1950    10 1.1      bus
    2 1960    20 2.2      bus
    3 1970    30 3.3      bus
    4 1980    40 4.4      bus
    5 1950    20 1.1      car
    6 1960    20 2.2      car
    7 1970    40 3.3      car
    8 1980    40 4.4      car
    

    This will get the data into R:

    data <- structure(list(Year = structure(c(1L, 2L, 3L, 4L, 1L, 2L, 3L, 
    4L), class = "factor", .Label = c("1950", "1960", "1970", "1980"
    )), score = c(10, 20, 30, 40, 20, 20, 40, 40), sd = c(1.1, 2.2, 
    3.3, 4.4, 1.1, 2.2, 3.3, 4.4), variable = c("bus", "bus", "bus", 
    "bus", "car", "car", "car", "car")), .Names = c("Year", "score", 
    "sd", "variable"), row.names = c(NA, -8L), class = "data.frame")
    

    And this will make the plot, with dodge an all. You properbly need the dodge, because your data is overlapping. You can control the amount of dodging with the “W” value.

    ggplot(data, aes(x=Year, y=score,col=variable))+
    geom_point(position=position_dodge(w=0.2))+
    geom_pointrange(aes(ymin=score-sd, ymax=score+sd,group=Year),position=position_dodge(w=0.2))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.