Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 以网格格式绘制几何点_R_Ggplot2 - Fatal编程技术网

R 以网格格式绘制几何点

R 以网格格式绘制几何点,r,ggplot2,R,Ggplot2,嗨,R和ggplot专家, 我开始学习R并尝试使用ggplot 我有一个用例,如下所述 可复制R代码: require(ggplot2) library(ggrepel) # Create the data frame. sales_data <- data.frame( emp_name = rep(c("Sam", "Dave", "John", "Harry", "Clark", "Kent", "Kenneth", "Richard", "Clement", "Toby",

嗨,R和ggplot专家, 我开始学习R并尝试使用
ggplot

我有一个用例,如下所述

可复制R代码

require(ggplot2)
library(ggrepel)

# Create the data frame.
sales_data <- data.frame(
  emp_name = rep(c("Sam", "Dave", "John", "Harry", "Clark", "Kent", "Kenneth", "Richard", "Clement", "Toby", "Jonathan"), times = 3), 
  month = as.factor(rep(c("Jan", "Feb", "Mar", "Jan", "Feb", "Mar", "Jan", "Feb", "Mar", "Jan", "Jan"), times = 3)),
  dept_name = as.factor(rep(c("Production", "Services", "Support", "Support", "Services", "Production", "Production", "Support", "Support", "Support", "Production"), times = 3)), 
  revenue = rep(c(100, 200, 300, 400, 500, 600, 500, 400, 300, 200, 500), times = 3),
  status = rep(c("Low", "Medium", "Medium", "High", "Very High", "Very High", "Very High", "High", "Medium", "Medium", "Low"), times = 3)
)

sales_data$month <- factor(sales_data$month, levels = c("Jan", "Feb", "Mar"))
month_vector <- levels(sales_data$month)
sales_data$month <- as.integer(sales_data$month)

sales_data$status <- factor(sales_data$status, levels = c("Low", "Medium", "High", "Very High"))

dept_vector <- levels(sales_data$dept_name)
sales_data$dept_name <- as.integer(sales_data$dept_name)

ggplot(sales_data, aes(x = month, y = dept_name)) +
  geom_raster(data = expand.grid(sales_data$month, sales_data$dept_name),
              aes(x = Var1, y = Var2, width=1, height=1), fill = NA, col = 'gray50', lty = 1) +

  geom_point(aes(size = status ), 
             shape = 16, position = position_jitter(seed = 0), show.legend = F) +
  scale_color_manual(name = "revenue") +
  geom_text(aes(label = revenue), size=4, vjust = 1.6, position = position_jitter(seed = 0)) + 

  theme_bw() +
  theme(
    axis.title = element_blank(),
    axis.ticks = element_blank(),
    plot.background = element_blank(), 
    axis.line = element_blank(), 
    panel.border = element_blank(), 
    panel.grid = element_blank(),

    axis.text = element_text(colour = "blue", face = "plain", size =11)
  ) +

  scale_x_continuous(limits=c(0.5,3.5), expand = c(0,0), breaks = 1:length(month_vector), labels = month_vector) +
  scale_y_continuous(limits=c(0.5,3.5), expand = c(0,0), breaks = 1:length(dept_vector), labels = dept_vector) +

  geom_hline(yintercept = as.numeric(sales_data$dept_name) + 0.5) +
  geom_vline(xintercept = as.numeric(sales_data$month) - 0.5, color = "grey")
require(ggplot2)
图书馆(ggrepel)
#创建数据帧。

销售数据您可能想看看#ozacha:我也使用了
ggrepel
,但使用抖动的几何点有时仍然与cricles重叠。这是示例数据,但在我的真实数据中,有更多的点和太多的重叠。也许我刚才问的这个问题的答案有帮助,尽管我的问题是关于标签而不是点:我认为
ggpointgrid::geom_pointrect()
可能与您描述的非常接近,@Om Sao:你可能想看看#ozacha:我也用过
ggrepel
,但使用抖动的geom_点有时还是会重叠在cricles上。这是样本数据,但在我的真实数据中,有更多的点和太多的重叠也许我刚才问的这个问题的答案有帮助,尽管我的问题是关于标签而不是点:我认为
ggpointgrid::geom_pointrect()
可能非常接近你所描述的,@Om Sao: