I have a table with 16k rows, where I made a graph in ggplot with it. But the subtitles are many and I would like to show only a part of them in a uniform range.
elevation<-read.csv("http://wesleysc352.github.io/perfil_elev_miranda.csv", sep=";", header = TRUE)%>%
as.data.frame()%>%
mutate_at(c('distancia', 'cota'), as.numeric)%>%
mutate(dist_km=((distancia)/1000))%>%
mutate_at(vars(dist_km, distancia), funs(round(., 2)))
ggplot(elevation, aes(x=as.factor(dist_km), y=cota))+
geom_point(size=0.1, color="red")+
ggtitle("Profile Elevation river")+
xlab("Dist(km)")+
ylab("Elevation(m)")+
theme_light()+
theme(plot.title = element_text(size=13))+
theme(axis.text.x=element_text(angle=90))+
scale_x_discrete(breaks=seq(0,555, by=50))
I tried to use the following command scale_x_discrete(breaks=seq(0,555, by=50)) to segment every 50 km but it didn’t work, because the intervals were not uniform and it doesn’t even show the last distance 555km.
>Solution :
Not sure if this is what you’re looking for. If you want to have x-axis from 0 to 550 at 50 interval, you don’t need to set dist_km to factor. Then use scale_x_continuous for setting breaks.
library(tidyverse)
ggplot(elevation, aes(x=dist_km, y=cota))+
geom_point(size=0.1, color="red")+
ggtitle("Profile Elevation river")+
xlab("Dist(km)")+
ylab("Elevation(m)")+
theme_light()+
theme(plot.title = element_text(size=13))+
theme(axis.text.x=element_text(angle=90))+
scale_x_continuous(breaks=seq(0,555, by=50))

