5

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.

catastrophic-failure
  • 3,759
  • 1
  • 24
  • 43
AyeTown
  • 831
  • 1
  • 5
  • 20
  • 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 ... ? – Ben Bolker Nov 09 '20 at 01:46
  • 1
    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. – NotAName Nov 09 '20 at 01:50
  • I am using the plotnine python module to utilize ggplot2. I'm running python in a terminal window. – AyeTown Nov 09 '20 at 01:58

1 Answers1

7

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

enter image description here

mt1022
  • 16,834
  • 5
  • 48
  • 71