0

enter image description here

I wish to create a plot as the above with data such as this,

data1=data.frame("School"=c(1,2,3,4,5,6,7,8,9,10), "Score"=c(80,64,79,64,64,89,69,71,61,98), "ScoreLow"=c(65,62,62,60,60,84,54,55,55,69), "ScoreHigh"=c(98,79,85,97,88,95,97,90,79,99)) 

The blue line is 'Score' and score is on the Y-AXIS and 'SChool' is on the X-AXIS. The length of the black line gets determined from 'ScoreLow' and 'ScoreHigh'

2 Answers 2

2

geom_errorbar would also work, in case you want to add some ticks at the edges (or leave them out, setting width=0, as below):

library(ggplot2) data1=data.frame("School"=c(1,2,3,4,5,6,7,8,9,10), "Score"=c(80,64,79,64,64,89,69,71,61,98), "ScoreLow"=c(65,62,62,60,60,84,54,55,55,69), "ScoreHigh"=c(98,79,85,97,88,95,97,90,79,99)) ggplot(data1, aes(x=School, y=Score)) + geom_line(colour="#507bc7", size=2)+ geom_errorbar(aes(ymin=ScoreLow, ymax=ScoreHigh), width=0, col="black", size=1.5) + theme_minimal() 

Created on 2020-04-10 by the reprex package (v0.3.0)

Sign up to request clarification or add additional context in comments.

Comments

1

I think you are looking for a combination of geom_line() and geom_segment().

library(ggplot2) ggplot(data1) + geom_line(aes(x = School, y = Score), color = "blue", size = 1.5) + geom_segment(aes(x = School, xend = School, y = ScoreLow, yend = ScoreHigh), size = 2) + scale_x_continuous(breaks = 1:10) + scale_y_continuous(limits = c(0, 100), breaks = 0:10 * 10) + theme_minimal() 

Need to probably play around a bit to get it how you want it. example plot

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.