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
• 10,620 points
980 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
• 910 points

Related Questions In Data Analytics

+3 votes
2 answers

Error: could not find function - R Programming

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

answered Aug 23, 2019 in Data Analytics by anonymous
• 33,030 points
33,710 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
• 52,350 points
2,534 views
+2 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
• 52,350 points
9,572 views
0 votes
1 answer
+10 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 9, 2018 in Data Analytics by Abhi
• 3,720 points
1,639 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,840 points
742 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
• 910 points
22,120 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
• 910 points
924 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP