I am new to ggplot2 and would appreciate a little help please
I am playing around with famous IRIS flower dataset.
This code is working great in Python 3 script.
c_col = ["#2f4858", "#f6ae2d", "#f26419",
"#33658a", "#55dde0", "#2f4858",
"#2f4858", "#f6ae2d", "#f26419",
"#33658a", "#55dde0", "#2f4858"]
fig = (
ggplot(data.dropna(subset = ['sepal_length'])) +
geom_point(
aes(x = 'sepal_length',
y = 'sepal_width'),
fill = c_col[10], color = 'blue'
) +
labs(
title ='Relationship between sepal_length and sepal_width',
x = 'sepal_length',
y = 'sepal_width',
))
I was wondering how to add a feature to plot three different colors depending on flower species... above code plots all three flower species in BLUE color... but I would like to have three colors in my Scatered diagram... so that every flower specie is in its own color.
Here is an example based on the iris dataset (you appear to have something based on it):
ggplot(iris) +
geom_point(
aes(x = Sepal.Length,
y = Sepal.Width,
colour = Species)
) +
labs(
title ='Relationship between sepal_length and sepal_width',
x = 'sepal_length',
y = 'sepal_width'
)
Assuming it works the same as R's ggplot2, then just move the colour bit into the aes() function to vary the species by colour. You'll also want scale_colour_manual() to pick from your list of colours..
If you're using the Python implementation of ggplot2 (ggplot) http://ggplot.yhathq.com/ in Python, you might have better luck asking on Stack Overflow or a Python forum, if no one has the answers for you here.
There's a notebook full of examples in the repo here: