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

边栏推荐
- 动态内存(进阶四)
- How to Visualize Missing Data in R using a Heatmap
- 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
- Some problems encountered in introducing lvgl into esp32 Arduino
- Power Spectral Density Estimates Using FFT---MATLAB
- Summary of flutter problems
- A white hole formed by antineutrons produced by particle accelerators
- ROS lacks catkin_ pkg
- Order by注入
- vant tabs组件选中第一个下划线位置异常
猜你喜欢

6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
![[idea] use the plug-in to reverse generate code with one click](/img/b0/00375e61af764a77ea0150bf4f6d9d.png)
[idea] use the plug-in to reverse generate code with one click

The computer screen is black for no reason, and the brightness cannot be adjusted.

制造业数字化转型和精益生产什么关系

Redis exceeds the maximum memory error oom command not allowed when used memory & gt; ' maxmemory'

基于Hardhat和Openzeppelin开发可升级合约(一)

Compilation errors and printout garbled problems caused by Chinese content in vs2019 code

JS -- take a number randomly from the array every call, and it cannot be the same as the last time

多文件程序X32dbg动态调试

R HISTOGRAM EXAMPLE QUICK REFERENCE
随机推荐
easyExcel和lombok注解以及swagger常用注解
JS -- take a number randomly from the array every call, and it cannot be the same as the last time
Summary of flutter problems
Is it safe to open a stock account online? I'm a novice, please guide me
时间格式化显示
进入前六!博云在中国云管理软件市场销量排行持续上升
6. Introduce you to LED soft film screen. LED soft film screen size | price | installation | application
Is the stock account given by qiniu business school safe? Can I open an account?
2022年遭“挤爆”的三款透明LED显示屏
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
php 根据经纬度查询距离
Precautions for scalable contract solution based on openzeppelin
What week is a date obtained by QT
Introduction to interface debugging tools
K-Means Clustering Visualization in R: Step By Step Guide
PLC-Recorder快速监控多个PLC位的技巧
程序员成长第六篇:如何选择公司?
Develop scalable contracts based on hardhat and openzeppelin (I)
excel表格中选中单元格出现十字带阴影的选中效果
【多线程】主线程等待子线程执行完毕在执行并获取执行结果的方式记录(有注解代码无坑)