当前位置:网站首页>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
)

边栏推荐
- 解决uniapp列表快速滑动页面数据空白问题
- 可升级合约的原理-DelegateCall
- 亚马逊云科技 Community Builder 申请窗口开启
- How to Create a Nice Box and Whisker Plot in R
- Array splitting (regular thinking
- 通过券商经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
- ASTParser 解析含有emum 枚举方法的类文件的踩坑记
- Native method merge word
- Homer forecast motif
- RPA advanced (II) uipath application practice
猜你喜欢

ESP32存储配网信息+LED显示配网状态+按键清除配网信息(附源码)

Wechat applet uses Baidu API to achieve plant recognition

抖音海外版TikTok:正与拜登政府敲定最终数据安全协议

ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
![[cloud native] 2.5 kubernetes core practice (Part 2)](/img/87/826894d758392a0c7a60dd5fa09eef.png)
[cloud native] 2.5 kubernetes core practice (Part 2)

Verilog and VHDL signed and unsigned number correlation operations

亚马逊云科技 Community Builder 申请窗口开启

Principe du contrat évolutif - delegatecall

Develop scalable contracts based on hardhat and openzeppelin (II)

JS -- take a number randomly from the array every call, and it cannot be the same as the last time
随机推荐
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
Visualization of chip SEQ data by deeptools
在连接mysql数据库的时候一直报错
Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting
Astparser parsing class files with enum enumeration methods
Jenkins installation
基于Hardhat和Openzeppelin开发可升级合约(一)
ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?
ctf 记录
liftOver进行基因组坐标转换
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
Amazon cloud technology community builder application window opens
Complement (Mathematical Simulation
enumrate的start属性的坑
How to Create a Beautiful Plots in R with Summary Statistics Labels
RPA advanced (II) uipath application practice
可昇級合約的原理-DelegateCall
Verilog 和VHDL有符号数和无符号数相关运算
PKG package manager usage instance in FreeBSD
A white hole formed by antineutrons produced by particle accelerators