当前位置:网站首页>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
)
边栏推荐
- Fabric.js 3个api设置画布宽高
- Liftover for genome coordinate conversion
- 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
- PX4 Position_ Control RC_ Remoter import
- How to Create a Nice Box and Whisker Plot in R
- Implementation of address book (file version)
- Mmrotate rotation target detection framework usage record
- map集合赋值到数据库
- php 根据经纬度查询距离
猜你喜欢
II Stm32f407 chip GPIO programming, register operation, library function operation and bit segment operation
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示
Wechat applet uses Baidu API to achieve plant recognition
Amazon cloud technology community builder application window opens
在连接mysql数据库的时候一直报错
GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
RPA advanced (II) uipath application practice
Some problems encountered in introducing lvgl into esp32 Arduino
Seriation in R: How to Optimally Order Objects in a Data Matrice
How to Create a Beautiful Plots in R with Summary Statistics Labels
随机推荐
Always report errors when connecting to MySQL database
Visualization of chip SEQ data by deeptools
The selected cells in Excel form have the selection effect of cross shading
Some problems encountered in introducing lvgl into esp32 Arduino
HOW TO ADD P-VALUES ONTO A GROUPED GGPLOT USING THE GGPUBR R PACKAGE
Homer预测motif
时间格式化显示
[visual studio 2019] create MFC desktop program (install MFC development components | create MFC application | edit MFC application window | add click event for button | Modify button text | open appl
PHP query distance according to longitude and latitude
6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用
C # method of obtaining a unique identification number (ID) based on the current time
Develop scalable contracts based on hardhat and openzeppelin (I)
Order by injection
微信小程序利用百度api达成植物识别
The position of the first underline selected by the vant tabs component is abnormal
在连接mysql数据库的时候一直报错
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
由粒子加速器产生的反中子形成的白洞
PHP 2D and multidimensional arrays are out of order, PHP_ PHP scrambles a simple example of a two-dimensional array and a multi-dimensional array. The shuffle function in PHP can only scramble one-dim
Homer forecast motif