没有图例的棒棒糖和使用 R 的两个轴标签

Lollipop without Legend and Both Axis Labels Using R

我想为我正在种植的特定 r 包装贴纸绘制 Lollipop chart。我想要它没有 legend,没有 x-axis,没有 y-axis 我想要的只是一个简单的情节。

我有什么

df1 <- read.table(text =
                    "nbb_RMSE  9 0.2402482
                    mbb_RMSE  9 0.1023012
                    cbb_RMSE  8 0.2031448
                    tmbb_RMSE 4 0.2654746
                    tcbb_RMSE 9 0.4048711")

colnames(df1) <- c("Methods", "lb", "RMSE")

df1 |>
  dplyr::mutate(colour = fct_reorder(Methods, RMSE)) |>
  ggplot2::ggplot(aes(Methods, RMSE, colour = colour)) + 
  ggplot2::geom_point(size = 4) + 
  ggplot2::geom_segment(aes(Methods, xend = Methods, yend = RMSE, y = 0)) + 
  ggplot2::scale_color_manual(values = c("green", "yellowgreen", "yellow", 
                            "orange", "red"),
                 labels = c(9, 8, 9, 9, 4), name = "lb") + 
  ggplot2::theme_bw(base_size = 16)

这里是

我想要的

我要

您可以为 theme 中不需要的元素设置 element_blank()

library(tidyverse)
library(forcats)

df1 <- read.table(text =
                    "nbb_RMSE  9 0.2402482
                    mbb_RMSE  9 0.1023012
                    cbb_RMSE  8 0.2031448
                    tmbb_RMSE 4 0.2654746
                    tcbb_RMSE 9 0.4048711")

colnames(df1) <- c("Methods", "lb", "RMSE")

df1 |>
  dplyr::mutate(colour = fct_reorder(Methods, RMSE)) |>
  ggplot2::ggplot(aes(Methods, RMSE, colour = colour)) + 
  ggplot2::geom_point(size = 4) + 
  ggplot2::geom_segment(aes(Methods, xend = Methods, yend = RMSE, y = 0)) + 
  ggplot2::scale_color_manual(values = c("green", "yellowgreen", "yellow", 
                                         "orange", "red"),
                              labels = c(9, 8, 9, 9, 4), name = "lb") + 
  ggplot2::theme_bw(base_size = 16) +
  theme(panel.border = element_blank(),
        legend.position = "none",
        axis.title = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank())

reprex package (v2.0.1)

创建于 2022-06-04