R programming error: Plot error - “Col=”red“

0 votes

I'm trying to draw a plot in R:

Here's my code:

g<- function(x,y)
  + x**2+y**2-3*x+y+2
gb<- function(x) g(x[1],x[2])
x <- seq(-2,2,len=51)
y <- seq(-2,2,len=51)
gz<-outer(x,y,g)
contour(x,y,gz)
polygon(c(0,0,1),c(1,2,1))

The above code works fine but when I try to add color to my plot using the following code:

 g<- function(x,y)
  + x**2+y**2-3*x+y+2
gb<- function(x) g(x[1],x[2])
x <- seq(-2,2,len=51)
y <- seq(-2,2,len=51)
gz<-outer(x,y,g)
contour(x,y,gz)
polygon(c(0,0,1),c(1,2,1),
        + col="red",
        +density=c(30,40))

I get this error:

Error: unexpected '=' in:
"polygon(c(0,0,1),c(1,2,1),
        + col="
May 28, 2019 in Data Analytics by Sophie may
• 9,940 points
48 views

1 answer to this question.

0 votes

Fix this line:

polygon(c(0,0,1),c(1,2,1), col="red", density=c(30,40))
answered May 28, 2019 by Zulaikha
• 890 points

Related Questions In Data Analytics

0 votes
2 answers

Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

answered Aug 22, 2019 in Data Analytics by anonymous
• 32,440 points
8,646 views
0 votes
1 answer

"no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 51,830 points
164 views
0 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 51,830 points
3,190 views
0 votes
1 answer
+9 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Anmol
• 3,680 points
109 views
+1 vote
2 answers
0 votes
1 answer

R programming logic

Use gsub to match the substring that we want ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,800 points
48 views
0 votes
1 answer
0 votes
1 answer

R programming error: { : missing value where TRUE/FALSE needed "

This should work: for ( i in 1:dim(m)[[1]] ...READ MORE

answered May 28, 2019 in Data Analytics by Zulaikha
• 890 points
3,556 views
0 votes
1 answer

Changing variable values using R programming

This should work: df$symbol <- as.character(df$symbol) df$symbol[df$symbol == "ABCD.BO"] ...READ MORE

answered May 27, 2019 in Data Analytics by Zulaikha
• 890 points
49 views