Skip to main content

Hi

I am using the R caller for creating a scatter plot with 2 variables and I would like using 2 different colors for the 2 variables. I am using the following function:

plot(wells, col = c("red", "blue"))

Yet it comes out black!

Any ideas

 

Best regards,

 

Felipe Verdú

Hi Felipe. It's hard to know what might be going on without seeing the rest of your workflow. Feel free to upload your workspace here as a template, or provide a minimal reproducible example using R.

Your code looks correct. As written, it would create a single scatterplot if wells contains two columns and randomly color the points red or blue. If wells contains more than one column it would display a scatterplot matrix with random red or blue points. Is that the result you want? 

If you want to color the wells by some other factor, you'll have to change your code. You can simply set col to a factor, as shown in the answer here:

data<-iris 
plot(data$Sepal.Length, data$Sepal.Width, col=data$Species)
legend(7,4.3,unique(data$Species),col=1:length(data$Species),pch=1)

You might also consider using the popular ggplot2 package instead, which I greatly prefer to the graphics::plot() function.


Hi @samatsafe,

I am sorry that I didn't get back to you before. The problem was actually that the inspector wasn't creating the correct diagram for some reason (it was yet black). It turned out that after I had to restart my workbench the 2 colors suddenly appeared. A bug for inspector? I am not sure.

Thanks for your answer anyway!

Br,

@felipeverdu1


Hi @samatsafe,

I am sorry that I didn't get back to you before. The problem was actually that the inspector wasn't creating the correct diagram for some reason (it was yet black). It turned out that after I had to restart my workbench the 2 colors suddenly appeared. A bug for inspector? I am not sure.

Thanks for your answer anyway!

Br,

@felipeverdu1

Good to hear you found a solution. If you run into it that problem with the Inspector again, please do file a bug.


Reply