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

边栏推荐
- The selected cells in Excel form have the selection effect of cross shading
- 预言机链上链下调研
- Wechat applet uses Baidu API to achieve plant recognition
- K-Means Clustering Visualization in R: Step By Step Guide
- Develop scalable contracts based on hardhat and openzeppelin (I)
- GGPUBR: HOW TO ADD ADJUSTED P-VALUES TO A MULTI-PANEL GGPLOT
- Visualization of chip SEQ data by deeptools
- GGPlot Examples Best Reference
- Writing contract test cases based on hardhat
- 基于Hardhat编写合约测试用例
猜你喜欢

HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R

【2022 ACTF-wp】

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

The position of the first underline selected by the vant tabs component is abnormal

MySQL comparison operator in problem solving

亚马逊云科技 Community Builder 申请窗口开启

On April 17, 2022, the five heart matchmaker team received double good news

Wechat applet uses Baidu API to achieve plant recognition

Amazon cloud technology community builder application window opens

Tiktok overseas tiktok: finalizing the final data security agreement with Biden government
随机推荐
2022年遭“挤爆”的三款透明LED显示屏
Is it safe to open a stock account through the QR code of the securities manager? Or is it safe to open an account in a securities company?
Some problems encountered in introducing lvgl into esp32 Arduino
The position of the first underline selected by the vant tabs component is abnormal
liftOver进行基因组坐标转换
Order by injection
[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
HOW TO EASILY CREATE BARPLOTS WITH ERROR BARS IN R
CTF record
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
Basic usage of MySQL in centos8
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)
Eight sorting summaries
The selected cells in Excel form have the selection effect of cross shading
mysql 基本语句
Programmer growth Chapter 6: how to choose a company?
map集合赋值到数据库
Liftover for genome coordinate conversion
Redis超出最大内存错误OOM command not allowed when used memory &gt; 'maxmemory'
pgsql 字符串转数组关联其他表,匹配 拼接后原顺序展示