2014-11-02 7 views
-1

R에 문제가 있으며 도움을 주시면 감사하겠습니다.R 부도 불평등 R

나는 다음과 같은 제약을위한 가능성의 영역을 플롯 할 수 있습니다

constrains: 
5*x + 3*y >= 210 
x + y <= 110 
4*x + y <= 200 

어떤 아이디어? 또한 나는 가능한 것을 색칠 할 필요가있다.

+2

http://stackoverflow.com/questions/15385063/easiest-way-to-plot-inequalities-with-hatched-fill에서보세요 – NPE

답변

2

편도, 덧글의 링크 이외에 선형 제약 조건을 가진 영역을 그리는 데 특별히 적합한 geom_ribbon을 사용하는 것이 좋습니다.

enter image description here

library(ggplot2) 

fun1 <- function(x) 210/3 -5/3*x 
fun2 <- function(x) 110 -x 
fun3 <- function(x) 200 -4*x 
x1 = seq(-5,100) 
mydf = data.frame(x1, y1=fun1(x1), y2=fun2(x1),y3= fun3(x1)) 
mydf <- transform(mydf, z = pmax(y1,pmin(y2,y3))) 
ggplot(mydf, aes(x = x1)) + 
    geom_line(aes(y = y1), colour = 'blue') + 
    geom_line(aes(y = y2), colour = 'green') + 
    geom_line(aes(y = y3), colour = 'red') + 
    geom_ribbon(aes(ymin=y1,ymax = z), fill = 'gray60')