气泡图中分类 x 轴和 y 轴的顺序颠倒了吗?如何反推?
Order of categorical x and y axis in bubble chart reversed? How to unreverse?
这是我的数据头部:
structure(list(asutus = c("Eesti Draamateater", "Eesti Draamateater",
"Eesti Draamateater", "Eesti Noorsooteater", "Eesti Noorsooteater",
"Eesti Noorsooteater", "Rahvusooper Estonia", "Rahvusooper Estonia",
"Rakvere Teatrimaja", "Rakvere Teatrimaja", "Rakvere Teatrimaja",
"Rakvere Teatrimaja", "Sakala Teatrimaja", "Vene Teater", "Vene Teater",
"Vene Teater", "Vene Teater"), hoone_liik = structure(c(2L, 1L,
3L, 2L, 4L, 1L, 2L, 1L, 2L, 4L, 1L, 3L, 1L, 2L, 4L, 1L, 3L), .Label = c("teatrihoone",
"ladu", "töökojad", "muu"), class = "factor"), hoone_suletud_netopind = c(2441.1,
6004, 705.8, 672, 970.8, 3509, 2337.6, 12426.7, 973, 3307.4,
4478, 446.6, 3220, 394.8, 281.5, 5873.9, 373.7)), row.names = c(NA,
-17L), groups = structure(list(asutus = c("Eesti Draamateater",
"Eesti Noorsooteater", "Rahvusooper Estonia", "Rakvere Teatrimaja",
"Sakala Teatrimaja", "Vene Teater"), .rows = structure(list(1:3,
4:6, 7:8, 9:12, 13L, 14:17), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, 6L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
我的颜色:
prx_col_palette <- function(){
c("#E69F00",
"#56B4E9",
"#009E73",
"#F0E442",
"#0072B2",
"#D55E00",
"#CC79A7")
}
prx_cols <- prx_col_palette()
我的气泡图:
ggplot(pindalad_joonisele,
aes(x = str_to_title(hoone_liik),
y = str_to_title(reorder(asutus, desc(asutus))),
colour = str_to_title(hoone_liik),
size = hoone_suletud_netopind)) +
geom_point() +
geom_text(aes(label = hoone_suletud_netopind),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_size_continuous(range = c(13, 35)) + # Adjust as required.
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())
我希望 y 轴和 x 轴的顺序如下:
pindalad_joonisele$asutus <- factor(pindalad_joonisele$asutus, levels = c("Eesti Draamateater", "Eesti Noorsooteater",
"Rahvusooper Estonia", "Rakvere Teatrimaja", "Sakala Teatrimaja",
"Vene Teater"))
pindalad_joonisele$hoone_liik <- factor(pindalad_joonisele$hoone_liik, levels = c("teatrihoone", "ladu", "töökojad", "muu"))
但是,似乎没有任何效果,而且它们的顺序颠倒或随机。有人可以帮我解决这个问题吗?谢谢!
同样,我不明白这个问题的全部内容。我喜欢这个情节,它很容易理解。在我看来,ggplot's
x
和 y
变量定义不正确。还添加了 scale_y_discrete(limits = rev)
以更改顺序 top-to-bottom。
示例代码:
pindalad_joonisele$asutus <- factor(pindalad_joonisele$asutus, levels = c("Eesti Draamateater", "Eesti Noorsooteater",
"Rahvusooper Estonia", "Rakvere Teatrimaja", "Sakala Teatrimaja",
"Vene Teater"))
pindalad_joonisele$hoone_liik <- factor(pindalad_joonisele$hoone_liik, levels = c("teatrihoone", "ladu", "töökojad", "muu"))
ggplot(pindalad_joonisele,
aes(x = hoone_liik,
y = asutus,
colour = hoone_liik,
size = hoone_suletud_netopind)) +
geom_point() +
geom_text(aes(label = hoone_suletud_netopind),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_y_discrete(limits = rev) # reverse y axis
scale_size_continuous(range = c(13, 35)) + # Adjust as required.
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())
剧情:
这是我的数据头部:
structure(list(asutus = c("Eesti Draamateater", "Eesti Draamateater",
"Eesti Draamateater", "Eesti Noorsooteater", "Eesti Noorsooteater",
"Eesti Noorsooteater", "Rahvusooper Estonia", "Rahvusooper Estonia",
"Rakvere Teatrimaja", "Rakvere Teatrimaja", "Rakvere Teatrimaja",
"Rakvere Teatrimaja", "Sakala Teatrimaja", "Vene Teater", "Vene Teater",
"Vene Teater", "Vene Teater"), hoone_liik = structure(c(2L, 1L,
3L, 2L, 4L, 1L, 2L, 1L, 2L, 4L, 1L, 3L, 1L, 2L, 4L, 1L, 3L), .Label = c("teatrihoone",
"ladu", "töökojad", "muu"), class = "factor"), hoone_suletud_netopind = c(2441.1,
6004, 705.8, 672, 970.8, 3509, 2337.6, 12426.7, 973, 3307.4,
4478, 446.6, 3220, 394.8, 281.5, 5873.9, 373.7)), row.names = c(NA,
-17L), groups = structure(list(asutus = c("Eesti Draamateater",
"Eesti Noorsooteater", "Rahvusooper Estonia", "Rakvere Teatrimaja",
"Sakala Teatrimaja", "Vene Teater"), .rows = structure(list(1:3,
4:6, 7:8, 9:12, 13L, 14:17), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, 6L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
我的颜色:
prx_col_palette <- function(){
c("#E69F00",
"#56B4E9",
"#009E73",
"#F0E442",
"#0072B2",
"#D55E00",
"#CC79A7")
}
prx_cols <- prx_col_palette()
我的气泡图:
ggplot(pindalad_joonisele,
aes(x = str_to_title(hoone_liik),
y = str_to_title(reorder(asutus, desc(asutus))),
colour = str_to_title(hoone_liik),
size = hoone_suletud_netopind)) +
geom_point() +
geom_text(aes(label = hoone_suletud_netopind),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_size_continuous(range = c(13, 35)) + # Adjust as required.
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())
我希望 y 轴和 x 轴的顺序如下:
pindalad_joonisele$asutus <- factor(pindalad_joonisele$asutus, levels = c("Eesti Draamateater", "Eesti Noorsooteater",
"Rahvusooper Estonia", "Rakvere Teatrimaja", "Sakala Teatrimaja",
"Vene Teater"))
pindalad_joonisele$hoone_liik <- factor(pindalad_joonisele$hoone_liik, levels = c("teatrihoone", "ladu", "töökojad", "muu"))
但是,似乎没有任何效果,而且它们的顺序颠倒或随机。有人可以帮我解决这个问题吗?谢谢!
同样,我不明白这个问题的全部内容。我喜欢这个情节,它很容易理解。在我看来,ggplot's
x
和 y
变量定义不正确。还添加了 scale_y_discrete(limits = rev)
以更改顺序 top-to-bottom。
示例代码:
pindalad_joonisele$asutus <- factor(pindalad_joonisele$asutus, levels = c("Eesti Draamateater", "Eesti Noorsooteater",
"Rahvusooper Estonia", "Rakvere Teatrimaja", "Sakala Teatrimaja",
"Vene Teater"))
pindalad_joonisele$hoone_liik <- factor(pindalad_joonisele$hoone_liik, levels = c("teatrihoone", "ladu", "töökojad", "muu"))
ggplot(pindalad_joonisele,
aes(x = hoone_liik,
y = asutus,
colour = hoone_liik,
size = hoone_suletud_netopind)) +
geom_point() +
geom_text(aes(label = hoone_suletud_netopind),
colour = "white",
size = 3.5) +
scale_x_discrete(position = "top")+
scale_y_discrete(limits = rev) # reverse y axis
scale_size_continuous(range = c(13, 35)) + # Adjust as required.
scale_colour_manual(values = prx_cols)+
labs(x = NULL, y = NULL) +
theme(legend.position = "none",
panel.background = element_blank(),
panel.grid = element_blank(),
axis.text.x = element_text(size=11),
axis.text.y = element_text(size=11),
axis.ticks = element_blank())
剧情: