当前位置:网站首页>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
)
边栏推荐
- Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
- PHP tea sales and shopping online store
- MySql存储过程游标遍历结果集
- Basic usage of MySQL in centos8
- Attribute acquisition method and operation notes of C # multidimensional array
- Installation of ROS gazebo related packages
- Amazon cloud technology community builder application window opens
- 6方面带你认识LED软膜屏 LED软膜屏尺寸|价格|安装|应用
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- SSRF
猜你喜欢
excel表格中选中单元格出现十字带阴影的选中效果
HOW TO CREATE AN INTERACTIVE CORRELATION MATRIX HEATMAP IN R
【IDEA】使用插件一键逆向生成代码
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
How to Create a Beautiful Plots in R with Summary Statistics Labels
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
由粒子加速器产生的反中子形成的白洞
RPA进阶(二)Uipath应用实践
GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
Cluster Analysis in R Simplified and Enhanced
随机推荐
How to Create a Nice Box and Whisker Plot in R
Some things configured from ros1 to ros2
Webauthn - official development document
Verilog 和VHDL有符号数和无符号数相关运算
PowerBI中导出数据方法汇总
ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
GGPlot Examples Best Reference
SSRF
Principle of scalable contract delegatecall
Pit of the start attribute of enumrate
八大排序汇总
解决uniapp列表快速滑动页面数据空白问题
ctf 记录
tidb-dm报警DM_sync_process_exists_with_error排查
spritejs
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
MySQL comparison operator in problem solving
PHP tea sales and shopping online store
RPA advanced (II) uipath application practice
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)