현재 CSV에서 읽고있는 데이터 세트의 열 하나만 보여주는 산점도가 있습니다. ATI와 BTI를 모두 플로팅하고 싶습니다.
PP BTI ATI
1 9710 9660
2 10000 9900
3 10300 10100
4 10600 10400
.
.
.
99 159000 107000
내 코드는 다음과 같습니다.
#server.R
#Income Percentile Scatterplot
incomedata <- read.csv("/Users/mathewsayer/Documents/Work/Level 7/Shiny Flat Tax/Flat Tax App/data/incomedist.csv")
ranges <- reactiveValues(x = NULL, y = NULL)
output$plot1 <- renderPlot({
ggplot(incomedata, aes(x = BTI, y = PP)) +
geom_point() +
coord_cartesian(xlim = ranges$x, ylim = ranges$y)
})
#Brush and zoom on scatterplot
observeEvent(input$plot1_dblclick, {
brush <- input$plot1_brush
if (!is.null(brush)) {
ranges$x <- c(brush$xmin, brush$xmax)
ranges$y <- c(brush$ymin, brush$ymax)
}
else {
ranges$x <- NULL
ranges$y <- NULL
}
})
다음과 같이 ATI를 추가해 보았지만 aes(x = BTI:ATI, y = PP)
오류 메시지가 나타납니다.Aesthetics must be either length 1 or the same as the data (99): x, y
데이터를 프레임이나 테이블로 부르는 것이 더 나을까요? 어떤 도움이라도 대단히 감사하겠습니다.
편집 : 검은 색 플롯 포인트는 BTI입니다. ATI의 데이터가 방금 한 사진 모형과 비슷하게 나타나기를 원합니다.
백분위 수가 y 축에있는 이유는 모르겠지만 원하는 작업을 수행하는 코드는 다음과 같습니다.
library(dplyr)
library(shiny)
library(tidyr)
library(ggplot2)
# simulate some data
df_foo = data_frame(
percentile = seq.int(99),
ATI = sort(rnorm(99)),
BTI = sort(rnorm(99))
)
# UI
ui_foo = shinyUI(
plotOutput("plot_foo")
)
# server
server_foo = shinyServer(function(input, output) {
output$plot_foo = renderPlot({
df_foo %>%
gather(key = var_name, value = value, -percentile) %>%
ggplot(aes(x = value, y = percentile, group = var_name, color = var_name)) +
geom_line() +
theme_bw()
})
})
# run the server
shinyApp(ui = ui_foo, server = server_foo)
귀하의 질문은 ggplot2
기본적으로 여러 변수를 그리는 방법에 관한 것이며 group
적절하게 재구성 된 데이터에서 기본적으로 미학을 지정해야합니다 .
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다