0

Hi I have a dataset in which I have countries and investigator email 2 columns that I want to use and rest other data. WHen trying to create a bar chart using R and Shiny, I am getting below error:

Aesthetics must be either length 1 or the same as the data (806): x, y

In bar chart, I want to show the count of investigators for each country with countries on x axis and no of investigators on Y.

ui.R

shinyUI(fluidPage(

  #title of the page
  titlePanel("No of Investigator by Country and Sponsor"),

  sidebarLayout(

    sidebarPanel(),

    #placeholder for bar pannel
    mainPanel(
      fluidRow(
        column(width = 6,plotlyOutput("investogatorByCountry")) ,

        column(width = 6,plotlyOutput("investogatorBySponsor"))
      )
    )
  )
))


server.R

shinyServer(function(input,output){

  #code for investigator by country
  output$investogatorByCountry <- renderPlotly({

    #reading the data file
    whoData <- read.csv(file="ICTRP-Results.csv", header=TRUE, sep = ",")

    #counting no of investigators in country
    investigatorCount <- count(whoData, vars = c("Contact_Email"))

    Countries <- whoData$Countries

    #print(investigatorCount)

    p <- ggplot(data = investigatorCount, aes(x=Countries, y=Contact_Email)) + geom_bar(stat = "identity")

  })
})
Vaibhav
  • 105
  • 1
  • 8
  • 1
    That error has nothing to with `shiny`, its the error produced by `ggplot`. If you could provide a sample data it would be easier to identify the problem. There seems to be some inconsistency in your data. – SBista Jun 01 '17 at 12:11
  • here is the link to sample data..there were many other columns as well but only 2 i.e. country and contact_email are useful to us https://drive.google.com/file/d/0ByozdBy0HsNWcGhOWDRiRTg5a0U/view?usp=sharing – Vaibhav Jun 01 '17 at 12:24
  • Looking at the code I think your `investigatorCount` data does not have a column named `Countries` or `Contact_Email`. – SBista Jun 01 '17 at 13:11
  • yes..worked for me. Thanks. One more query..I want to check how many unique Contact_Email are there against each unique country. I modified code to below but that gives no of records against each country. I want it to consider contact_email also. Please suggest investigatorCount <- count(whoData, vars = "Countries") – Vaibhav Jun 01 '17 at 13:18
  • I guess you want [this](https://stackoverflow.com/questions/17421776/how-to-add-count-of-unique-values-by-group-to-r-data-frame) – SBista Jun 01 '17 at 13:44

0 Answers0