ggplot气泡图自定义颜色 [英] ggplot bubble graph custom colors

查看:190
本文介绍了ggplot气泡图自定义颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个要使用自定义颜色的数据框

  data<-data.frame(condition = c('1','1','1','1','1','2','2','2','2','2','3','3','3','3','3'),评估等级= c('400','410','420','430','440','500','510','520','530','540','300','310','320','330','340'),Freq = c('1','2','1','5','7','9','1','5','3','4','5','8','1','3','5'),MathGrade = c('A +','B-','C-','D','F','A-','B','C +','D-','F','A +','D','D','F','C'),Condition = c('条件1','条件1','条件1','条件1','条件1','条件2','条件2','条件2','条件2','条件2','条件3','条件3','条件3','条件3"','条件3')) 

我使用ggplot来获取气泡图,但我想知道如何对其进行编辑以使用公司的标准颜色

  p<-ggplot(数据,aes(x = MathGrade,y =评估等级,大小=频率,填充=条件))+geom_point(aes(colour = Condition))+ggtitle(主要标题")+实验室(x =第一数学成绩",y =数学评估分数") 

我有一个称为颜色的向量:

 颜色[1]#101820"#AF272F"#EAAA00" 

并且我试图用这个来画图:

p<-p + scale_fill_manual(值=颜色)

什么都没有改变.我尝试按照

I have this dataframe that I'm trying to use custom colors

data <- data.frame(condition=c('1','1','1','1','1','2','2','2','2','2','3','3','3','3','3'), AssessmentGrade=c('400','410','420','430','440','500','510','520','530','540','300','310','320','330','340'), Freq=c('1','2','1','5','7','9','1','5','3','4','5','8','1','3','5'), MathGrade=c('A+','B-','C-','D','F','A-','B','C+','D-','F','A+','D','D','F','C'), Condition=c('Condition 1','Condition 1','Condition 1','Condition 1','Condition 1','Condition 2','Condition 2','Condition 2','Condition 2','Condition 2','Condition 3','Condition 3','Condition 3','Condition 3','Condition 3'))

I used ggplot to get abubble graph but I was wondering how I would edit it to use my company's standard colors

p <- ggplot(data, aes(x = MathGrade, y = AssessmentGrade, size = Freq, fill = Condition)) +
 geom_point(aes(colour = Condition)) +
 ggtitle("Main Title") +
 labs(x = "First Math Grade", y = "Math Assessment Score")

I have a vector called colors:

colors
[1] "#101820" "#AF272F" "#EAAA00" 

and I tried to graph it with this:

p <- p + scale_fill_manual(values = color)

nothing changed. I tried following directions here but nothing changed. Can someone assist?

解决方案

You create a palette:

my_colors<- c("#101820", "#AF272F", "#EAAA00")

Then when it comes time you use that in your plot:

 p <- ggplot(data, aes(x = MathGrade, y = AssessmentGrade, size = Freq, fill = Condition)) +
 geom_point(shape=21) +
 ggtitle("Main Title") +
 labs(x = "First Math Grade", y = "Math Assessment Score") +
 scale_fill_manual(values=my_colors) #or you could enter the color numbers directly here

This worked during testing but ggplot does not like how you used size in the main aesthetic.

这篇关于ggplot气泡图自定义颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆