如何在R代码中使重叠圆的每个部分成为不同的颜色?

时间:2017-06-13 20:39:18

标签: r shiny

我不想改变圆圈的透明度,但我想让图表的每个部分都有不同的颜色。例如,圆圈A为红色,圆圈B为黄色。然后交叉部分是橙色。我怎么能在R?中做到这一点?

UI

library(shiny)
shinyUI(fluidPage(
  titlePanel("Probability"),
  sidebarLayout(
    sidebarPanel(

  h4(p("Choose radiuses of the circle and see change of probability")),

  sliderInput("radius",
              "Radius 1",
              min = 0,
              max = 1,
              value = 0.5),
  sliderInput("radius2",
              "Radius 2",
              min = 0,
              max = 1,
              value = 0.5),
  sliderInput("radius3",
              "Radius 3",
              min = 0,
              max = 1,
              value = 0.5) 
),

# Show a plot of the generated distribution
mainPanel(
  plotOutput("distPlot")
)
  )
))

服务器

library(shiny)
library(plotrix)
library(grid)

shinyServer(function(input, output) {

  output$distPlot <- renderPlot({

    isolate({
      plot(c(-2,2),c(-2,2), type = 'n')

    })

    col1 <- rgb(red = .0, green = 0, blue = 0.8, alpha = 0.8)
    col2 <- rgb(red = .9, green = 0.9, blue = 0, alpha = 0.8)
    col3 <- rgb(red = 0.8, green = 0, blue = 0.5, alpha = 0.8)
    draw.circle(-0.5,0,input$radius,col=col1)
    draw.circle(0.5,0,input$radius2,col=col2)
    draw.circle(0,-1,input$radius3,col=col3)

  },width=500,height = 500)

})

0 个答案:

没有答案