ggplot2由具有重复的变量形成

时间:2015-06-09 14:27:20

标签: r ggplot2 shapes

我在Dropbox的Excel中附加了表格 我想根据国家和三个基本颜色(黑色,红色和蓝色)制作一个情节和形状(例如,24,22,21,21,21,24,25,23)由Brand和finallay添加平均值置信区间。

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

这就是我得到的:

http://i.imgur.com/675uwuE.png

问题在于我不能为每个品牌选择我想要的形状。

谢谢

1 个答案:

答案 0 :(得分:0)

除了你有一个错字(形状而不是形状 s ),你需要设置一个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))