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

在R语言中构建带产品标注的BCG矩阵可视化需求

Build a BCG Matrix in R with Product Labels

Got it, let's walk through building your BCG matrix step by step in R. First, we need to clean up that percentage data (since it's stored as strings with the % sign), then we'll use ggplot2 to create the plot, add quadrant dividers, and label each product right next to its coordinate point.

Step 1: Prepare and Clean the Data

First, let's replicate your sample data and convert those percentage strings to numeric values so we can plot them:

# Create sample data frame (matches your structure)
df <- data.frame(
  Product = c("A", "B", "C", "D"),
  `Market Share` = c("15%", "14%", "20%", "89%"),
  `Market Growth` = c("23%", "15%", "58%", "90%"),
  stringsAsFactors = FALSE
)

# Clean percentage columns: remove % symbol and convert to numeric
df$`Market Share` <- as.numeric(gsub("%", "", df$`Market Share`))
df$`Market Growth` <- as.numeric(gsub("%", "", df$`Market Growth`))

Step 2: Define BCG Quadrant Thresholds

Classic BCG uses 10% market growth as the Y-axis cutoff, and relative market share (vs. the top competitor) as the X-axis cutoff. Since you specified using absolute market share for the X-axis, we'll use the median of your market share values as the divider (you can adjust this to your industry's benchmark if needed):

# Set threshold values
growth_cutoff <- 10  # Classic BCG growth threshold
share_cutoff <- median(df$`Market Share`)  # Adjust this to your business needs

Step 3: Plot the BCG Matrix with Product Labels

We'll use ggplot2 for the plot, add dashed lines for quadrants, and label each product next to its data point:

library(ggplot2)

# Build the BCG matrix
ggplot(df, aes(x = `Market Share`, y = `Market Growth`)) +
  # Add quadrant divider lines
  geom_vline(xintercept = share_cutoff, linetype = "dashed", color = "gray50") +
  geom_hline(yintercept = growth_cutoff, linetype = "dashed", color = "gray50") +
  # Add data points for each product
  geom_point(size = 3, color = "#2c3e50") +
  # Add product labels (adjust hjust/vjust to move labels if needed)
  geom_text(aes(label = Product), hjust = 0.5, vjust = -1.2, color = "#e74c3c", fontface = "bold") +
  # Add quadrant names for clarity (optional)
  annotate("text", x = max(df$`Market Share`) * 0.75, y = max(df$`Market Growth`) * 0.75,
           label = "Stars", size = 5, fontface = "bold") +
  annotate("text", x = max(df$`Market Share`) * 0.75, y = min(df$`Market Growth`) * 1.25,
           label = "Cash Cows", size = 5, fontface = "bold") +
  annotate("text", x = min(df$`Market Share`) * 1.25, y = max(df$`Market Growth`) * 0.75,
           label = "Question Marks", size = 5, fontface = "bold") +
  annotate("text", x = min(df$`Market Share`) * 1.25, y = min(df$`Market Growth`) * 1.25,
           label = "Dogs", size = 5, fontface = "bold") +
  # Customize titles and labels
  labs(title = "BCG Matrix", x = "Market Share (%)", y = "Market Growth (%)") +
  # Clean up the theme for readability
  theme_minimal() +
  theme(plot.title = element_text(hjust = 0.5, size = 16, face = "bold"),
        axis.title = element_text(size = 12),
        axis.text = element_text(size = 10))

Bonus: Fix Overlapping Labels

If your product labels overlap, use the ggrepel package to automatically adjust their positions to avoid clutter:

# Install if needed: install.packages("ggrepel")
library(ggrepel)

# Replace the geom_text line with this:
geom_text_repel(aes(label = Product), color = "#e74c3c", fontface = "bold")

Notes for Customization

  • Relative Market Share: For a true BCG matrix (per the original framework), replace absolute market share with relative share (your product's share divided by the top competitor's share). Calculate it with:
    df$Relative_Share <- df$`Market Share` / max(df$`Market Share`)
    
    Then use Relative_Share as the X-axis, with a cutoff of 1 (products with share >= the top competitor fall in the right quadrants).
  • Adjust Thresholds: Tweak growth_cutoff and share_cutoff to match your industry's specific benchmarks (e.g., use the industry average growth rate instead of the classic 10%).

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:03:54