当前位置:网站首页>GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
GGPLOT: HOW TO DISPLAY THE LAST VALUE OF EACH LINE AS LABEL
2022-07-02 09:41:00 【小宇2022】
# Load required R packages
library(tidyverse)
library(ggrepel)
# Set ggplot2 default theme to theme_bw()
theme_set(theme_bw())
# Demo data
df <- tibble::tribble(
~Species, ~Petal.Length, ~Petal.Width, ~Sepal.Length, ~Sepal.Width,
"setosa", 1.462, 0.246, 5.006, 3.428,
"versicolor", 4.26, 1.326, 5.936, 2.77,
"virginica", 5.552, 2.026, 6.588, 2.974
)
df_long <- df %>%
pivot_longer(
Petal.Length:Sepal.Width,
names_to = "variable", values_to = "value"
)
# Basic line plot
lp <- ggplot(df_long, aes(x = Species, y = value, group = variable)) +
geom_line(aes(color = variable)) +
geom_point() +
theme(legend.position = "top")
# Filter the last values and add onto the line plot
# Corresponds to the `virginica` species
data_ends <- df_long %>% filter(Species == "virginica")
lp +
geom_text_repel(
aes(label = value), data = data_ends,
fontface ="plain", color = "black", size = 3
)

边栏推荐
猜你喜欢

揭露数据不一致的利器 —— 实时核对系统

PLC-Recorder快速监控多个PLC位的技巧

解决uniapp列表快速滑动页面数据空白问题

Win11 arm system configuration Net core environment variable

Cluster Analysis in R Simplified and Enhanced

八大排序汇总

How to Create a Nice Box and Whisker Plot in R

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

Thanos Receiver

亚马逊云科技 Community Builder 申请窗口开启
随机推荐
STM32 single chip microcomputer programming learning
电脑无缘无故黑屏,无法调节亮度。
mysql链表数据存储查询排序问题
Cluster Analysis in R Simplified and Enhanced
C # method of obtaining a unique identification number (ID) based on the current time
GGPlot Examples Best Reference
LVM operation
ctf 记录
Introduction to interface debugging tools
QT获取某个日期是第几周
Internship report skywalking distributed link tracking?
MySql存储过程游标遍历结果集
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
How to Create a Nice Box and Whisker Plot in R
微信小程序利用百度api达成植物识别
Eight sorting summaries
Some things configured from ros1 to ros2
可昇級合約的原理-DelegateCall
The difference between SQL left join main table restrictions written after on and where
R HISTOGRAM EXAMPLE QUICK REFERENCE