我有以下关于牛仔裤的数据,我希望它以最容易理解的方式绘制,重点是可用的尺寸。
jeans <- tribble(~ category, ~ brand, ~size_value,
"Jeans","BE GANESHA","38",
"Jeans","BE GANESHA","40",
"Jeans","BE GANESHA","42",
"Jeans","BE GANESHA","44",
"Jeans","BE GANESHA","34",
"Jeans","BE GANESHA","36",
"Jeans","Bendita Be","M",
"Jeans","Bendita Be","XL",
"Jeans","By Florencia","0",
"Jeans","By Florencia","1",
"Jeans","By Florencia","2",
"Jeans","By Florencia","3",
"Jeans","CLARA AGUAYO","U",
"Jeans","Caro Criado","L",
"Jeans","Caro Criado","M",
"Jeans","Caro Criado","XS",
"Jeans","Caro Criado","S",
"Jeans","Caro Criado","XL",
"Jeans","Joséphine","32",
"Jeans","Joséphine","34",
"Jeans","Joséphine","36",
"Jeans","Joséphine","38",
"Jeans","Joséphine","40",
"Jeans","LAS MARCAS","L",
"Jeans","LAS MARCAS","M",
"Jeans","LAS MARCAS","S",
"Jeans","LAS MARCAS","XL",
"Jeans","LAS MARCAS","XS",
"Jeans","LAS MARCAS","XXL",
"Jeans","LIMITE","1",
"Jeans","LIMITE","2",
"Jeans","LIMITE","3",
"Jeans","LIMITE","4",
"Jeans","LIMITE","5",
"Jeans","LIMITE","6",
"Jeans","LIMITE","0",
"Jeans","MARIMBA MULTIMARCAS","31",
"Jeans","MUTMA","26",
"Jeans","MUTMA","27",
"Jeans","MUTMA","28",
"Jeans","MUTMA","29",
"Jeans","MUTMA","30",
"Jeans","MUTMA","31",
"Jeans","Margara Shaw","L",
"Jeans","Margara Shaw","M",
"Jeans","Margara Shaw","S",
"Jeans","Margara Shaw","XL",
"Jeans","Margara Shaw","XS",
"Jeans","Margara Shaw","XXL",
"Jeans","Margara Shaw","4XL")
jeans_pants %>%
mutate(size_value = case_when(
size_value == "S/M" ~ "S/M ",
size_value == "M/L" ~ "M/L ",
size_value == "L/XL" ~ "L/XL ",
size_value == "S/M" ~ "S/M ",
size_value == "M/L" ~ "M/L ",
size_value == "L/XL" ~ "L/XL ",
size_value == "XL" ~ "XL ",
size_value == "XXL" ~ "XXL ",
size_value == "XXXL" ~ "XXXL ",
.default = as.character(size_value)),
size_value = factor(size_value, levels = c("U", "0", "1", "2", "3", "4", "5",
"6",
"S/M ", "M/L ", "L/XL ",
"XXS", "XS", "S", "M", "L", "XL ",
"XXL ", "XXXL ", "4XL",
"22", "23", "24", "25", "26", "27",
"28", "29", "30", "31", "32", "33",
"34", "36", "38", "40", "42",
"44"))) %>%
arrange(brand, desc(size_value)) %>%
ggplot(aes(size_value, brand)) +
geom_point(aes(color = size_value), alpha = .6, size = 3) +
scale_color_manual(values = rep(c("#8E6151", "#988880"), 38)) +
theme(legend.position = "none",
panel.border = element_blank(),
panel.grid.minor.x = element_blank(),
axis.text.x = element_text(margin = margin(r = 22))))
首先,我想在相同比例的点之间画一条线(我将展示一张所需服装的图片)。然后,我尝试手动在轴XL,XXL和XXXL中进行空间设置,但我做不到。
我真的很感激帮助和任何进一步的建议可视化。
在这里我留下了一个品牌的例子,有多种尺寸的规模:
data <- tribble(~brand,~size_value,
"BE GANESHA","38",
"BE GANESHA","40",
"BE GANESHA","42",
"BE GANESHA","44",
"BE GANESHA","34",
"BE GANESHA","36",
"Margo Baridon","24",
"Margo Baridon","26",
"Margo Baridon","28",
"Margo Baridon","30",
"Margo Baridon","32",
"Margo Baridon","34",
"BE GANESHA","M",
"BE GANESHA","L",
"BE GANESHA","S",
"BE GANESHA","XL",
"BE GANESHA","XS",
"BE GANESHA","XXL",
"Margo Baridon","L",
"Margo Baridon","M",
"Margo Baridon","S",
"Margo Baridon","XS",
"Margo Baridon","24",
"Margo Baridon","26",
"Margo Baridon","28",
"Margo Baridon","30",
"Margo Baridon","32",
"Margo Baridon","34",
"Margo Baridon","XL")
1条答案
按热度按时间ldxq2e6h1#
我认为
ggplot2
不支持离散轴上的任意间距(我很想找到这样的解决方案!在此期间,让我们转移到连续的x轴,基于期望的宽度预定义对应的x位置。(这样就不需要添加空格。)(The顺序和宽度是从前面的代码中推断出来的。)
我们会把这个
left_join
放到你的jeans
上。请注意,我并没有防范任何在sizes$size_value
中找不到的jeans$size_value
;如果发生这种情况,x=
将被指定为NA
,并且可能不会绘制。由于您希望在按
brand
分组的点之间添加线,因此我也将添加线(在点下面),尽管这是“仅仅因为”。我还添加了theme_bw()
来简化主题,更类似于你在问题中的演示。