You have following group of costumers described by variables age and spend in data frame df
ui <- fluidPage(
# Application title
# Sidebar with a slider input for number of bins
column(4, titlePanel ("Events IDs"),
numericInput("cel_id","IDs", value=5)
),
column(8,
plotOutput("plot")
)
)
# Show a plot of the generated distribution
# Define server logic required to draw a histogram
server <- function(input, output) {
data_plot <- reactive({
dta[cel_id == input$cel_id]
})
output$plot <- renderPlot({
# generate bins based on input$bins from ui.R
# ggplot(data_plot()[1:10,], aes(x = time, y = dec)) + geom_line()
ggplot(data_plot()[ x == x[2] & y == y[2]]) +
geom_tile(aes(x = time, y = 'P', fill = is.na(p) )) +
geom_tile(aes(x = time, y = 'Q', fill = is.na(Q) )) +
geom_tile(aes(x = time, y = 'sm', fill = is.na(sm) )) +
geom_tile(aes(x = time, y = 'EID' ), fill = 'black', dta = data_plot()[ x == x[1] & y == y[1] & !is.na(EID)]) +
scale_fill_manual(values = c('FALSE' = 'white', 5218740,"TRUE" = "red")) + theme_bw() + facet_wrap(dec ~ ., scale = 'free', ncol = 1)
})
}
The task is to divide the costumers into groups to help advertising team that wants to send more targeted emails.
We start with simple scatter plot:
Three distinct groups are already visible.
The task for you:
Use stats::k-means function similarly as it was shown during the lecture and produce a diaqgram with three costumers groups, something like this:
Ackowledgement:
https://www.guru99.com/r-k-means-clustering.html
Check it out…