How do I use scale_color_manual in Python?
Asked Answered
G

1

6

I've been using ggplot for a long time now and am very comfortable using it in R. I am working in Python right now for school and I am having the toughest time understanding this error. When I try to use scale_color_manual to manually assign colors to my variable called "CellTypeOther" which has unique values 0/1, I keep getting the following error:

NameError: name 'c' is not defined

Here is my code to create the ggplot:

from plotnine import * 
plot = (
  ggplot(Y_tsne,aes(x = 'X',y = 'Y'))
   + geom_point(aes(color = 'CellTypeOther'),alpha = 0.4,size = 2)
   + scale_color_manual(c("blue","red"))
)

The plot renders fine without the last line. Does anyone have any clue as to what might be going on? I can't share my data because it is sensitive.

Important note: I am using the plotnine Python module to utilize ggplot2.

Grefe answered 9/11, 2020 at 1:40 Comment(3)
This looks like straight R code. Can you clarify the context in which this is being used/called? Is this in a cell of a Jupyter notebook, or being used by some Python-to-R interface, or ... ?Toadfish
For python I'd assume c("blue", "red") should be a dictionary, although I haven't used ggplot in python so it's just a guess.Auberon
I am using the plotnine python module to utilize ggplot2. I'm running python in a terminal window.Grefe
M
8

You should use [] rather than c() in python:

enter image description here

Moralist answered 9/11, 2020 at 2:24 Comment(1)
ugh... knew I should have asked sooner. Thanks!Grefe

© 2022 - 2024 — McMap. All rights reserved.