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

边栏推荐
- Homer forecast motif
- Develop scalable contracts based on hardhat and openzeppelin (II)
- 基于Hardhat编写合约测试用例
- 由粒子加速器产生的反中子形成的白洞
- How to Visualize Missing Data in R using a Heatmap
- spritejs
- VS2019代码中包含中文内容导致的编译错误和打印输出乱码问题
- 电脑无缘无故黑屏,无法调节亮度。
- Win11 arm system configuration Net core environment variable
- Is bond fund safe? Does the bond buying foundation lose principal?
猜你喜欢

From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang

Attribute acquisition method and operation notes of C # multidimensional array

GGPlot Examples Best Reference

揭露数据不一致的利器 —— 实时核对系统

Eight sorting summaries

【云原生】2.5 Kubernetes 核心实战(下)

R HISTOGRAM EXAMPLE QUICK REFERENCE

PKG package manager usage instance in FreeBSD

解决uniapp列表快速滑动页面数据空白问题

GGHIGHLIGHT: EASY WAY TO HIGHLIGHT A GGPLOT IN R
随机推荐
PLC-Recorder快速监控多个PLC位的技巧
Programmer growth Chapter 6: how to choose a company?
接口调试工具概论
电脑无缘无故黑屏,无法调节亮度。
Homer预测motif
Never forget, there will be echoes | hanging mirror sincerely invites you to participate in the opensca user award research
SQLite modify column type
通过券商经理的开户二维码开股票账户安全吗?还是去证券公司开户安全?
What are the methods of adding elements to arrays in JS
Importerror: impossible d'importer le nom « graph» de « graphviz»
map集合赋值到数据库
Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'
R HISTOGRAM EXAMPLE QUICK REFERENCE
[idea] use the plug-in to reverse generate code with one click
spritejs
Webauthn - official development document
Redis超出最大内存错误OOM command not allowed when used memory &gt; 'maxmemory'
对毕业季即将踏入职场的年轻人的一点建议
STM32 single chip microcomputer programming learning
JS -- take a number randomly from the array every call, and it cannot be the same as the last time