Add Minor Tick Marks without Labels to ggplot2 Plot in R (Example) | Modify Axis Ticks & Grid Lines
Автор: Statistics Globe
Загружено: 2023-02-06
Просмотров: 1176
Описание:
How to draw additional minor tick marks without labels in a ggplot2 plot in the R programming language. More details: https://statisticsglobe.com/add-minor...
R code of this video:
data <- data.frame(x = 1:6, # Create example data frame
y = c(1, 3, 5, 2, 2, 4))
install.packages("ggplot2") # Install & load ggplot2 package
library("ggplot2")
ggp <- ggplot(data, aes(x, y)) + # Create ggplot2 plot with default axes
geom_line()
ggp # Draw ggplot2 plot with default axes
my_breaks <- seq(1, 6, by = 0.5) # Create sequence for new x-axis
my_breaks # Print sequence for new x-axis
ggp + # Draw ggplot2 plot with new x-axis
scale_x_continuous(breaks = my_breaks)
my_labels <- sprintf("%.1f", my_breaks) # Specify blanks for unnecesary labels
my_labels[c(1, 2, 4, 5, 6, 8, 9, 10)] <- ""
my_labels # Print updated labels
ggp + # Additional minor axis ticks without labels
scale_x_continuous(breaks = my_breaks,
labels = my_labels)
Follow me on Social Media:
Facebook – Statistics Globe Page: / statisticsglobecom
Facebook – R Programming Group for Discussions & Questions: / statisticsglobe
Facebook – Python Programming Group for Discussions & Questions: / statisticsglobepython
LinkedIn – Statistics Globe Page: / statisticsglobe
LinkedIn – R Programming Group for Discussions & Questions: / 12555223
LinkedIn – Python Programming Group for Discussions & Questions: / 12673534
Twitter: / joachimschork
Music by bensound.com
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: