You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

寻求R语言ggplot2下231个Band变量R²值的优化可视化方案

Hey there! Dealing with 231 data points can definitely make a basic scatter plot feel cluttered and hard to interpret—let's walk through a few publication-ready visualization strategies tailored to your spectral band vs. R² data. First, let's start with your sample data for context:

# Your sample data
df <- structure(list(
  Band = c(402, 411, 419, 427, 434),
  R.squared = c(0.044655015122032, 0.852028718800355, 0.818617476505653, 0.825782272278991, 0.860844967662728),
  Adj.Rsquared = c(-0.0614944276421867, 0.835587465333728, 0.798463862784058, 0.806424746976656, 0.845383297403031),
  Intercept = c(0.000142126282140086, -0.00373545760470339, -0.00258909036368109, 0.000626075834918527, -3.3448513588372e-05),
  Slope = c(-0.00108714482110104, 0.393380133190131, 0.443463459485279, 0.503881831479685, 0.480162723468755)
), row.names = c(NA, 5L), class = "data.frame")

1. Jittered Scatter + Smoothing Trend Line

This fixes overcrowding while showing both individual data points and the overall trend of R² across bands:

library(ggplot2)

ggplot(df, aes(x = as.factor(Band), y = R.squared)) +
  # Jitter points to reduce overlap; alpha prevents occlusion
  geom_jitter(width = 0.2, alpha = 0.6, color = "#2c3e50") +
  # Add loess smooth line with confidence interval to show trend
  geom_smooth(aes(x = Band, y = R.squared), method = "loess", se = TRUE, color = "#e74c3c", linewidth = 1) +
  labs(
    x = "Spectral Band",
    y = expression(R^2),
    title = "R² Values by Spectral Band",
    subtitle = "With Loess Smoothing Trend"
  ) +
  theme_bw() +
  theme(
    axis.text.x = element_text(angle = 45, hjust = 1),  # Rotate labels to avoid overlap
    plot.title = element_text(hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(hjust = 0.5)
  )

Best for: When you need to retain individual point visibility while highlighting how R² changes across bands.


2. Grouped Violin + Boxplot + Jitter

If you can group bands by meaningful intervals (e.g., visible vs. near-infrared), this plot balances distribution trends and individual data:

# Add a grouping column (adjust breaks to match your band ranges)
df$Band_Group <- cut(df$Band, breaks = c(400, 420, 440), labels = c("400-420 nm", "420-440 nm"))

ggplot(df, aes(x = Band_Group, y = R.squared)) +
  geom_violin(fill = "#3498db", alpha = 0.7) +  # Shows distribution density
  geom_boxplot(width = 0.2, color = "#2c3e50", outlier.shape = NA) +  # Highlights quartiles
  geom_jitter(width = 0.1, color = "#e74c3c", size = 1.5) +  # Adds individual points
  labs(
    x = "Band Interval",
    y = expression(R^2),
    title = "Distribution of R² Values by Band Intervals",
    subtitle = "Violin + Boxplot + Jittered Points"
  ) +
  theme_bw() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(hjust = 0.5)
  )

Best for: Comparing R² performance across predefined band groups—ideal for scientific publications where you need to emphasize group-level differences.


3. Sorted Band Heatmap

This lets you quickly spot high/low R² bands at a glance, with clean, compact formatting:

# Sort data by band to maintain wavelength order
df_sorted <- df[order(df$Band), ]
df_sorted$Band <- factor(df_sorted$Band, levels = df_sorted$Band)

ggplot(df_sorted, aes(x = Band, y = 1, fill = R.squared)) +
  geom_tile(color = "white") +  # Color-coded tiles for R²
  geom_text(aes(label = round(R.squared, 2)), color = "white", size = 3) +  # Optional: Show R² values
  scale_fill_viridis_c(option = "plasma", name = expression(R^2)) +  # Publication-friendly color scale
  labs(
    x = "Spectral Band",
    y = "",
    title = "R² Values by Sorted Spectral Band",
    subtitle = "Heatmap Visualization"
  ) +
  theme_minimal() +
  theme(
    axis.text.y = element_blank(),
    axis.ticks.y = element_blank(),
    plot.title = element_text(hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(hjust = 0.5)
  )

Best for: Rapidly identifying top-performing bands—great for supplementary figures in papers.


4. Sorted Line Plot with Markers

If your bands represent a continuous wavelength sequence, this plot highlights fluctuations in R² across the spectrum:

df_sorted <- df[order(df$Band), ]

ggplot(df_sorted, aes(x = Band, y = R.squared)) +
  geom_line(color = "#2c3e50", linewidth = 1) +  # Connects points to show trend
  geom_point(color = "#e74c3c", size = 2) +  # Marks individual band values
  labs(
    x = "Spectral Band",
    y = expression(R^2),
    title = "R² Trend Across Spectral Bands",
    subtitle = "Sorted by Wavelength"
  ) +
  theme_bw() +
  theme(
    plot.title = element_text(hjust = 0.5, face = "bold"),
    plot.subtitle = element_text(hjust = 0.5)
  )

Best for: Emphasizing how R² rises/falls with wavelength—perfect for showing spectral patterns in your regression performance.

内容的提问来源于stack exchange,提问作者bird

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.11 08:31:43