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

边栏推荐
- [cloud native] 2.5 kubernetes core practice (Part 2)
- What are the methods of adding elements to arrays in JS
- flutter 问题总结
- C#基于当前时间,获取唯一识别号(ID)的方法
- ctf 记录
- 微信小程序利用百度api达成植物识别
- ROS lacks xacro package
- Summary of data export methods in powerbi
- RPA advanced (II) uipath application practice
- GGPlot Examples Best Reference
猜你喜欢

Importerror: impossible d'importer le nom « graph» de « graphviz»

tidb-dm报警DM_sync_process_exists_with_error排查

Pit of the start attribute of enumrate

ren域名有价值吗?值不值得投资?ren域名的应用范围有哪些?

MySQL比较运算符IN问题求解

Win11 arm system configuration Net core environment variable

map集合赋值到数据库

HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R

数字化转型挂帅复产复工,线上线下全融合重建商业逻辑

RPA advanced (II) uipath application practice
随机推荐
SSRF
可升级合约的原理-DelegateCall
Installation of ROS gazebo related packages
vant tabs组件选中第一个下划线位置异常
Cluster Analysis in R Simplified and Enhanced
C#多维数组的属性获取方法及操作注意
Array splitting (regular thinking
Introduction to interface debugging tools
PYQT5+openCV项目实战:微循环仪图片、视频记录和人工对比软件(附源码)
MTK full dump grab
map集合赋值到数据库
Webauthn - official development document
2022年遭“挤爆”的三款透明LED显示屏
ros缺少catkin_pkg
How to Visualize Missing Data in R using a Heatmap
Liftover for genome coordinate conversion
webauthn——官方开发文档
Jenkins installation
基于Hardhat编写合约测试用例
亚马逊云科技 Community Builder 申请窗口开启