ggplot2 shapes by variables with replicates

282 views Asked by At

I have the table that I attach in the Excel in Dropbox I want to make a plot with three basic colours (black, red and blue) by Country and the shapes (e.g., 24, 22, 21, 21, 21, 24, 25, 23) by Brand and finallay add the mean with a confidence interval.

CAR <- read.table("clipboard", header=T, sep="\t", dec=".")
df <- data.frame(CAR)
ggplot(df, aes(x = PRICE, y = SPEED, colour = COUNTRY, shapes = BRAND))+
  geom_point(size = 3)+
  stat_summary(fun.data = "mean_cl_boot", colour = "green")
BRAND SPEED PRICE COUNTRY
AUDI 193 47805 GER
AUDI 225 47805 GER
AUDI 235 47805 GER
AUDI 190 47805 GER
AUDI 187 47805 GER
AUDI 233 47805 GER
AUDI 185 47805 GER
AUDI 191 47805 GER
AUDI 214 47805 GER
AUDI 186 47805 GER
AUDI 227 47805 GER
AUDI 209 47805 GER
AUDI 215 47805 GER
AUDI 234 47805 GER
AUDI 229 47805 GER
AUDI 239 47805 GER
AUDI 222 47805 GER
AUDI 211 47805 GER
AUDI 199 47805 GER
BMW 214 61623 GER
BMW 249 61623 GER
BMW 205 61623 GER
BMW 239 61623 GER
BMW 237 61623 GER
BMW 219 61623 GER
BMW 216 61623 GER
BMW 221 61623 GER
BMW 230 61623 GER
BMW 221 61623 GER
BMW 218 61623 GER
BMW 245 61623 GER
BMW 204 61623 GER
BMW 221 61623 GER
BMW 222 61623 GER
BMW 217 61623 GER
BMW 249 61623 GER
BMW 245 61623 GER
BMW 237 61623 GER
MERCEDES 195 61623 GER
MERCEDES 201 61623 GER
MERCEDES 236 61623 GER
MERCEDES 191 61623 GER
MERCEDES 215 61623 GER
MERCEDES 206 61623 GER
MERCEDES 201 61623 GER
MERCEDES 203 61623 GER
MERCEDES 217 61623 GER
MERCEDES 195 61623 GER
MERCEDES 201 61623 GER
MERCEDES 222 61623 GER
MERCEDES 231 61623 GER
MERCEDES 205 61623 GER
MERCEDES 211 61623 GER
MERCEDES 202 61623 GER
MERCEDES 230 61623 GER
MERCEDES 199 61623 GER
MERCEDES 193 61623 GER
LOTUS 184 47250 UK
LOTUS 172 47250 UK
LOTUS 181 47250 UK
LOTUS 181 47250 UK
LOTUS 181 47250 UK
LOTUS 185 47250 UK
LOTUS 185 47250 UK
LOTUS 175 47250 UK
LOTUS 175 47250 UK
LOTUS 187 47250 UK
LOTUS 183 47250 UK
LOTUS 181 47250 UK
LOTUS 187 47250 UK
LOTUS 184 47250 UK
LOTUS 176 47250 UK
LOTUS 188 47250 UK
LOTUS 179 47250 UK
LOTUS 185 47250 UK
LOTUS 190 47250 UK
SEAT 160 21578 ES
SEAT 160 21578 ES
SEAT 165 21578 ES
SEAT 163 21578 ES
SEAT 183 21578 ES
SEAT 188 21578 ES
SEAT 188 21578 ES
SEAT 167 21578 ES
SEAT 184 21578 ES
SEAT 180 21578 ES
SEAT 174 21578 ES
SEAT 183 21578 ES
SEAT 188 21578 ES
SEAT 166 21578 ES
SEAT 167 21578 ES
SEAT 175 21578 ES
SEAT 183 21578 ES
SEAT 164 21578 ES
SEAT 178 21578 ES
ROVER 177 35924 UK
ROVER 198 35924 UK
ROVER 175 35924 UK
ROVER 191 35924 UK
ROVER 195 35924 UK
ROVER 165 35924 UK
ROVER 195 35924 UK
ROVER 171 35924 UK
ROVER 190 35924 UK
ROVER 183 35924 UK
ROVER 171 35924 UK
ROVER 172 35924 UK
ROVER 198 35924 UK
ROVER 165 35924 UK
ROVER 174 35924 UK
ROVER 174 35924 UK
ROVER 200 35924 UK
ROVER 191 35924 UK
ROVER 188 35924 UK
OPEL 175 18793 GER
OPEL 183 18793 GER
OPEL 173 18793 GER
OPEL 171 18793 GER
OPEL 168 18793 GER
OPEL 180 18793 GER
OPEL 179 18793 GER
OPEL 177 18793 GER
OPEL 169 18793 GER
OPEL 178 18793 GER
OPEL 171 18793 GER
OPEL 184 18793 GER
OPEL 184 18793 GER
OPEL 183 18793 GER
OPEL 174 18793 GER
OPEL 178 18793 GER
OPEL 167 18793 GER
OPEL 179 18793 GER
OPEL 179 18793 GER
ROLLS 178 54261 UK
ROLLS 177 54261 UK
ROLLS 187 54261 UK
ROLLS 184 54261 UK
ROLLS 192 54261 UK
ROLLS 189 54261 UK
ROLLS 178 54261 UK
ROLLS 194 54261 UK
ROLLS 184 54261 UK
ROLLS 192 54261 UK
ROLLS 195 54261 UK
ROLLS 179 54261 UK
ROLLS 175 54261 UK
ROLLS 186 54261 UK
ROLLS 184 54261 UK
ROLLS 190 54261 UK
ROLLS 191 54261 UK
ROLLS 183 54261 UK
ROLLS 180 54261 UK

This is what I get:

https://i.stack.imgur.com/E80ie.png

The problem is that I can not select for each Brand the shape I want.

Thanks

1

There are 1 answers

0
agstudy On BEST ANSWER

Besides the fact that you have a typo in aes ( shape and not shapes) , you need to set a scale_shape_manual :

ggplot(DX, aes(x = PRICE, y = SPEED, colour = COUNTRY, shape = BRAND))+
  geom_point(size = 3)+
  stat_summary(fun.data = "mean_cl_boot", colour = "green") +
  scale_shape_manual(values=c( 24, 22, 21, 21, 21, 24, 25, 23))