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

边栏推荐
- TDSQL|就业难?腾讯云数据库微认证来帮你
- Rest (XOR) position and thinking
- Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
- From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
- MySQL basic statement
- Tdsql | difficult employment? Tencent cloud database micro authentication to help you
- JS -- take a number randomly from the array every call, and it cannot be the same as the last time
- HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
- Cluster Analysis in R Simplified and Enhanced
- Principe du contrat évolutif - delegatecall
猜你喜欢

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

2022年4月17日五心红娘团队收获双份喜报

Amazon cloud technology community builder application window opens

在连接mysql数据库的时候一直报错

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

JS——每次调用从数组里面随机取一个数,且不能与上一次为同一个

念念不忘,必有回响 | 悬镜诚邀您参与OpenSCA用户有奖调研

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

mysql链表数据存储查询排序问题

A sharp tool for exposing data inconsistencies -- a real-time verification system
随机推荐
Bedtools tutorial
tidb-dm报警DM_sync_process_exists_with_error排查
Solve the problem of data blank in the quick sliding page of the uniapp list
MySql存储过程游标遍历结果集
MySQL basic statement
八大排序汇总
ctf 记录
bedtools使用教程
原生方法合并word
Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
C#多维数组的属性获取方法及操作注意
从ros1到ros2配置的一些东西
微信小程序利用百度api达成植物识别
Is the Ren domain name valuable? Is it worth investing? What is the application scope of Ren domain name?
Resources reads 2D texture and converts it to PNG format
Summary of data export methods in powerbi
Native method merge word
亚马逊云科技 Community Builder 申请窗口开启
STM32 single chip microcomputer programming learning
PKG package manager usage instance in FreeBSD