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 in Data Analytics by Sophie may
• 9,330 points
11 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Fix this line:

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

Related Questions In Data Analytics

0 votes
1 answer

Error: could not find function - R Programming

This error usually occurs when a package ...READ MORE

answered Oct 29, 2018 in Data Analytics by Maverick
• 10,020 points
170 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
• 36,300 points
40 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
• 36,300 points
758 views
0 votes
1 answer
+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,020 points
18 views
0 votes
1 answer
0 votes
1 answer

Error saying "could not find function "shinyUI"" in shiny R

Its a small spelling mistake that you've ...READ MORE

answered Nov 28, 2018 in Data Analytics by Maverick
• 10,020 points
276 views
0 votes
1 answer
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 in Data Analytics by Zulaikha
• 640 points
10 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.