当前位置:网站首页>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
)
边栏推荐
- Astparser parsing class files with enum enumeration methods
- 基于 Openzeppelin 的可升级合约解决方案的注意事项
- CTF record
- 在连接mysql数据库的时候一直报错
- tidb-dm报警DM_sync_process_exists_with_error排查
- Is bond fund safe? Does the bond buying foundation lose principal?
- mysql链表数据存储查询排序问题
- Principle of scalable contract delegatecall
- From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
- 抖音海外版TikTok:正与拜登政府敲定最终数据安全协议
猜你喜欢
TDSQL|就业难?腾讯云数据库微认证来帮你
电脑无缘无故黑屏,无法调节亮度。
Summary of data export methods in powerbi
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
Skills of PLC recorder in quickly monitoring multiple PLC bits
tqdm的多行显示与单行显示
RPA进阶(二)Uipath应用实践
Redis超出最大内存错误OOM command not allowed when used memory &gt; 'maxmemory'
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
ctf 记录
随机推荐
Attribute acquisition method and operation notes of C # multidimensional array
基于Hardhat编写合约测试用例
php 根据经纬度查询距离
Astparser parsing class files with enum enumeration methods
Principe du contrat évolutif - delegatecall
Win11 arm system configuration Net core environment variable
ctf 记录
Complement (Mathematical Simulation
How to Create a Beautiful Plots in R with Summary Statistics Labels
Resources reads 2D texture and converts it to PNG format
Solve the problem of data blank in the quick sliding page of the uniapp list
从攻击面视角,看信创零信任方案实践
The difference between SQL left join main table restrictions written after on and where
八大排序汇总
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
亚马逊云科技 Community Builder 申请窗口开启
Wechat applet uses Baidu API to achieve plant recognition
CTF record
Array splitting (regular thinking
mysql链表数据存储查询排序问题