0

I'm hoping this will be a simple solution, but how do I assign a single color to every data point in my bubble chart? When I specify color= or fill=, despite my color specification (ex: color = "blue") it only ever comes out red.

I even added a new column in the data frame where all rows have the same categorical value "samecolor", which I assign as fill = samecolor and specify later using scale_color_manual(values = c('mediumorchid').

I have my full code here:

p.class <- ggplot(data_melt, aes(x=pond, y=variable)) + geom_point(aes(size = value, fill = samecolor), alpha = 0.75, shape = 21) + scale_color_manual(values = c("mediumorchid")) + #scale_fill_discrete(values = c("mediumorchid")) + theme(legend.position = "bottom", legend.box = "horizontal", legend.direction = "horizontal", panel.background = element_blank()) + xlab("") + ylab("Taxonomy (Class)") + theme_linedraw(base_size = 18) + theme(axis.text.x = element_text(angle=45, hjust = 1)) + theme(plot.title = element_text( size = 15, face = "bold")) 

where I have commented out scale_fill_discrete(), for that was for a trial run with fill = samecolor.

Thank you in advance!

For reproducibility, here is my dput() output of a toy data set:

> dput(data_melt) structure(list(pond = structure(c(1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 2L), .Label = c("GG", "LG", "SM"), class = "factor"), variable = c("taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa1", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa2", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa3", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa4", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5", "taxa5"), value = c(0.134328358208955, 0.00497512437810945, 0.00746268656716418, 0.0124378109452736, 0.054726368159204, 0.203980099502488, 0.114427860696517, 0.109452736318408, 0.154228855721393, 0.00746268656716418, 0.00497512437810945, 0.191542288557214, 0.0757575757575758, 0.0833333333333333, 0.113636363636364, 0.128787878787879, 0.0606060606060606, 0.0227272727272727, 0.121212121212121, 0.0303030303030303, 0.0303030303030303, 0.143939393939394, 0.159090909090909, 0.0303030303030303, 0.0797498045347928, 0.0867865519937451, 0.0781860828772478, 0.0766223612197029, 0.0750586395621579, 0.0594214229867084, 0.0969507427677873, 0.0953870211102424, 0.101641907740422, 0.0836591086786552, 0.0852228303362002, 0.0813135261923378, 0.0163934426229508, 0.0655737704918033, 0.0327868852459016, 0.0819672131147541, 0.0491803278688525, 0.114754098360656, 0.0983606557377049, 0.131147540983607, 0.147540983606557, 0.0819672131147541, 0.131147540983607, 0.0491803278688525, 0.088339222614841, 0.0918727915194346, 0.0848056537102474, 0.0812720848056537, 0.0989399293286219, 0.0777385159010601, 0.0742049469964664, 0.0777385159010601, 0.102473498233216, 0.0918727915194346, 0.0671378091872792, 0.0636042402826855), samecolor = c("color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color", "color")), row.names = c(NA, -60L), class = "data.frame") 
1
  • If you want to set the points all to the same color you most often want to use the aesthetic outside aes(). So code like geom_point(aes(size = value), alpha = 0.75, shape = 21, fill = "mediumorchid") would do it. Setting to a constant does not make legends. Commented Sep 16, 2020 at 22:04

1 Answer 1

2

Try this. It is better to use scale_fill_manual() with the desired color if you want to change your fill option. You can set any color you wish. Just take into account that fill and color are different aesthetics elements. That is why you got tomato color in your original color because you were tryning to change color when fill was turned on. Here the code:

library(ggplot2) #Code ggplot(data_melt, aes(x=pond, y=variable)) + geom_point(aes(size = value, fill = samecolor), alpha = 0.75, shape = 21) + scale_fill_manual(values = c("blue")) + #scale_fill_discrete(values = c("blue")) + theme(legend.position = "bottom", legend.box = "horizontal", legend.direction = "horizontal", panel.background = element_blank()) + xlab("") + ylab("Taxonomy (Class)") + theme_linedraw(base_size = 18) + theme(axis.text.x = element_text(angle=45, hjust = 1)) + theme(plot.title = element_text( size = 15, face = "bold")) 

Output:

enter image description here

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

1 Comment

Thank you again, Duck. I really appreciate your help with this question... and basically all my previous questions. Take care!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.