I'm building a Shiny application to create visualizations for output reports of a system that I have.
The report contains 3 fields I'm interested in: Address Code, Street Code and City Code.
The values of these fields are numeric codes which I have, the meanings of these codes is not important for the problem, I simply want to create a plot where I can see how many times was each code present for each of the columns (a separate plot for each field)
So for example, the DF looks like this
Address Code | Street Code | City Code
100 100 30
100 100 30
0 15 40
50
25 0
As you can see, the value of the code can also be null.
And the output I expect from this would be something like a horizontal bar plot showing
The Y axis would be the codes themselves, and the X axis would be the amount of times they were observed
So following the mock table, I want this:
ADDRESS CODES
100 --------------
75 -
50 -
25 -
0 -------
0 1 2 3
I saw [here][1] a way to approach the issue, but I keep running into errors.
output$plot_levels <- plotly::renderPlotly({
#loadData merely grabs the data and returns it as a data frame.
#loadData uses fread to read the data from a file. It handles the null values as "".
df <- loadData()
df %>%
select(-`Address Code`) %>%
gather() %>%
#filter(`Address Code` != "") %>%
ggplot(aes(`Address Code`, ..count..)) + geom_col()
})
I keep getting "ERROR: object 'Address Code' not found" in the app. The Address Code being referred to there is the one in the ggplot line.
So why is it saying that it doesn't exist? I already confirmed that the loadData method is reading the source file correctly, and the column name is indeed read as Address Code.
[1]: Plot table objects with ggplot?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…