Transform my data in percentage to build a geom_bar (position = full) in relation with the percentage

Hello everybody,

I have a dataset that is presented like that :

I need to convert my value in percentage and then draw a geom bar with the bar full matching the percentage.

I began like this : But obviously it's not working, can someone please help??? :frowning: Thank you very much all.

database <- dbGetQuery(con_im, "select * from blablablamydata")

database = data %>% 
  group_by(slice_name) %>%
  mutate(count=n()) %>% 
  ungroup() %>%
  spread(slice_name,fill=0) %>%
  mutate(Row_sum = "_c2", 
         Percentage = "_c2"/Row_sum)


ui <- shinyUI(fluidPage(titlePanel("Application usage and versions downloaded"),
                        checkboxGroupInput("checkgroup","Checkbox group",
                                           choices =list ("AppDownloadUsage",
                                           selected = "AppDownloadUsage", inline = TRUE),
                        plotOutput(outputId = "database",  width = "auto", height = "500px", click = NULL,
                                   dblclick = NULL, hover = NULL, hoverDelay = NULL,
                                   overDelayType = NULL, brush = NULL, clickId = NULL, hoverId = NULL,
                                   inline = FALSE))

server <- function(input, output) {
  graphe <- geom_bar(databse, aes(x 

shinyApp(ui = ui, server = server)

Hi melanie! Welcome!

It's hard for people to figure out exactly what you're looking for without being able to run your code. Screenshots of data can actually be problematic — they aren't always easy to read, and anybody who wants to help is stuck retyping your data before they can work with it themselves.

The best thing for you to do is to turn your question into a reproducible example. I'd leave shiny out of it for the time being — it's generally a good idea to get your plot working the way you want outside of shiny first. So a good reproducible example of your problem would include:

  • Data that other people can access; in your case, you could include something like your screenshot sample by doing this:
    1. First, run this line in the console (replace database with whatever the name of your data frame is):
    dput(head(database, 20))
    1. Copy the weird structure(...jumble of stuff...) output you got from the console
    2. Paste it into your reproducible example like this:
    sample_data <- # Paste all the `dput()` output right here 
  • Include your library() calls at the top of the example
  • Include the code that prepares your data for plotting
  • Include whatever you've got for the plotting code

When you're done, the whole thing might look like this:

sample_data <- structure(...jumble of stuff...)

plot_data <- sample_data %>% 
  group_by(slice_name) %>%
  mutate(count=n()) %>% 
  ungroup() %>%
  spread(slice_name,fill=0) %>%
  mutate(Row_sum = "_c2", 
         Percentage = "_c2"/Row_sum)

graphe <- geom_bar(databse, aes(x 

Can you give that a try?

1 Like