如何更改ggplot中数字的大小和颜色?

时间:2014-11-11 13:03:01

标签: r ggplot2

我想将自己的尺寸和颜色赋予下图中的数字。有什么建议吗?

cars    country name    number
car1    US  Porsche 1
car2    US  Porsche 0
car3    US  Porsche 0
car4    US  Porsche 0
car5    US  Porsche 0
car6    US  Porsche 0
car1    US  Benz    0
car2    US  Benz    1
car3    US  Benz    0
car4    US  Benz    0
car5    US  Benz    0
car6    US  Benz    1
car1    US  Audi    1
car2    US  Audi    0
car3    US  Audi    0
car4    US  Audi    1
car5    US  Audi    1
car6    US  Audi    0
car1    UK  Porsche 0
car2    UK  Porsche 0
car3    UK  Porsche 1
car4    UK  Porsche 1
car5    UK  Porsche 0
car6    UK  Porsche 1
car1    UK  Benz    0
car2    UK  Benz    0
car3    UK  Benz    0
car4    UK  Benz    0
car5    UK  Benz    1
car6    UK  Benz    1
car1    UK  Audi    1
car2    UK  Audi    1
car3    UK  Audi    1
car4    UK  Audi    0
car5    UK  Audi    1
car6    UK  Audi    1

代码:

qplot(名称,汽车,数据= a,尺寸=数字,颜色=名称)+ facet_grid(.~country)

输出

enter image description here

1 个答案:

答案 0 :(得分:2)

qplot(name, cars, data=df, size=number, color=name, shape=name)+
    facet_grid(.~country)+
    scale_colour_manual(values=c("gray","blue","pink"))+
    scale_size_continuous(range = c(5,10))+
    scale_shape_manual(values=c(5,6,15))