I have tried all solutions recommended in How to display only integer values on an axis using ggplot2. Unfortunately, I could not solve the issue with any of them.
I have created a Shiny app that produces line graphs of annual data on a variety of variables. This works out nicely for most parameterizations:
No non-integer breaks
However, if I choose certain time spans on the slider, it produces graphs that have non-integer breaks on the x-axis, which makes no sense for a yearly data.
With non-integer breaks
Edit: Here a minimal reproducible version of the application
library(tidyverse)
library(shiny)
options(scipen = 999)
# Data
data1<-data.frame(values = c(15500, 16300, 18200, 28300, 23500, 23700,
31500, 35800, 34700, 36900, 40000, 44700,
53300, 55800, 69800, 89500, 1.13E+5,
1.53E+5, 1.77E+5, 1.83E+5, 1.99E+5),
year = seq(1990, 2010, 1))
#Shiny app
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
sliderInput("period", "Year:", min = 1990, max = 2010, value = c(1990, 2010), sep = "")),
mainPanel(plotOutput("ggplot2"))))
server <- function(input, output) {
data1_subset <- reactive({
filter(data1, year >= input$period[1] & year <= input$period[2])
})
output$ggplot2 <- renderPlot({
ggplot(data = data1_subset(), aes(x = year, y = values)) +
geom_line(aes(color = "red")) +
scale_x_continuous(name = "Year") +
scale_color_discrete(guide=FALSE)+
theme_minimal()
})
}
shinyApp(ui = ui, server = server)
To see the problem, select e.g. time span 2000-2010
Is there any way to suppress non-integer breaks as there are clearly nonsensical with annual data?
Thanks a lot in advance for your help!