当前位置:网站首页>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 11:49:00 【Xiaoyu 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
)
边栏推荐
- CTF record
- Mmrotate rotation target detection framework usage record
- 可升级合约的原理-DelegateCall
- MySQL basic statement
- A white hole formed by antineutrons produced by particle accelerators
- Some suggestions for young people who are about to enter the workplace in the graduation season
- Summary of data export methods in powerbi
- pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
- 基于 Openzeppelin 的可升级合约解决方案的注意事项
- R HISTOGRAM EXAMPLE QUICK REFERENCE
猜你喜欢
II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
预言机链上链下调研
On April 17, 2022, the five heart matchmaker team received double good news
How to Add P-Values onto Horizontal GGPLOTS
K-Means Clustering Visualization in R: Step By Step Guide
基于Hardhat和Openzeppelin开发可升级合约(一)
由粒子加速器产生的反中子形成的白洞
Cluster Analysis in R Simplified and Enhanced
文件操作(详解!)
念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研
随机推荐
QT meter custom control
Data analysis - Matplotlib sample code
Esp32 stores the distribution network information +led displays the distribution network status + press the key to clear the distribution network information (source code attached)
2022年遭“挤爆”的三款透明LED显示屏
QT获取某个日期是第几周
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
File operation (detailed!)
deepTools对ChIP-seq数据可视化
mysql 基本语句
PgSQL string is converted to array and associated with other tables, which are displayed in the original order after matching and splicing
Astparser parsing class files with enum enumeration methods
How to Create a Nice Box and Whisker Plot in R
Precautions for scalable contract solution based on openzeppelin
On April 17, 2022, the five heart matchmaker team received double good news
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
vant tabs组件选中第一个下划线位置异常
How to Add P-Values onto Horizontal GGPLOTS
Principe du contrat évolutif - delegatecall
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
JS -- take a number randomly from the array every call, and it cannot be the same as the last time