-1

I am using R programming and I want to make automatically plots on numerical and categorical variables, with summary

I am using shiny library

  • Welcome to SO! Stack Overflow is not the place to ask others to write your code *for you*, though the community is very willing to help you solve specific problems you encounter whilst writing it *for yourself*. What have you tried so far and why didn't it work? You maximise your chance of getting a useful answer if you provide a minimal reproducible example. [This post](https://stackoverflow.com/help/minimal-reproducible-example) may help. – Limey Jan 28 '23 at 13:40

1 Answers1

0

Here is an example of creating a histogram for a numerical variable in shiny using ggplot2:

output$plot1 <- renderPlot({
  ggplot(data, aes(x = variable))+
geom_histogram(binwidth = 1)})
  • Thanks for Ur response but how will be automatically separate numerical and categorical variable and then how will draw automatically plots on the variables based – abdul majid Jan 29 '23 at 02:54
  • You can use the mutate function in the dplyr library to create a new variable with the value "numeric" or "factor" depending on the data type of the original variable. for (col in names(data)) { if (is.numeric(data[[col]])) { output[[paste0("plot_", col)]] <- renderPlot({ ggplot(data, aes(x = col)) + geom_histogram(binwidth = 1) }) } else if (is.factor(data[[col]])) { output[[paste0("plot_", col)]] <- renderPlot({ ggplot(data, aes(x = col)) + geom_bar() }) } } – Hà Nguyễn Jan 30 '23 at 01:14