我在極坐標中用 "position = stack "繪制了一個堆積柱狀圖。
ggplot(d, aes(Component, Freq,填充=Subtype2))
geom_bar(position = 'stack', stat = 'identity')
scale_x_discrete(expand = c(0。 03, 0.5)
scale_y_continuous('分布'。 擴展= c(0。 0)
scale_fill_nejm()
guides(fill = guide_legend(title = 'IHC subtype')
coord_polar(theta = 'y')
主題(panel.background = element_blank(),
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 0。 25),
axis.ticks = element_line(size = 0。 25),
軸。 title = element_text(size = 12),/span>
axis.text. y = element_text(size = 10), axis.text.
axis.text. x = element_text(size = 10))
為了在y軸的起點和終點之間增加一個空間,我在scale_y_continuous中添加了limits = c(0, 2000)。
ggplot(d, aes(Component, Freq,填充=Subtype2))
geom_bar(position = 'stack'。 stat = 'identity')
scale_x_discrete(expand = c(0。 03, 0.5)
scale_y_continuous('分布'。 擴展= c(0。 0)。 限制 = c(0。 2000))
scale_fill_nejm()
guides(fill = guide_legend(title = 'IHC subtype')
coord_polar(theta = 'y')
主題(panel.background = element_blank(),
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 0。 25),
axis.ticks = element_line(size = 0。 25),
軸。 title = element_text(size = 12),/span>
axis.text. y = element_text(size = 10), axis.text.
axis.text. x = element_text(size = 10))
接下來,我想在極坐標中繪制一個比例條形圖,我嘗試了下面的代碼:
我想在極坐標中繪制一個比例條形圖。
ggplot(d, aes(Component。 Freq,填充=Subtype2))
geom_bar(position = 'fill'。 stat = 'identity')
scale_x_discrete(expand = c(0。 03, 0.5)
scale_y_continuous('分布'。 擴展= c(0。 0)
scale_fill_nejm()
guides(fill = guide_legend(title = 'IHC subtype')
coord_polar(theta = 'y')
主題(panel.background = element_blank(),
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 0。 25),
axis.ticks = element_line(size = 0。 25),
軸。 title = element_text(size = 12),/span>
axis.text. y = element_text(size = 10), axis.text.
axis.text. x = element_text(size = 10))
我想用下面的代碼在y軸的起點和終點之間添加一個空格,但輸出結果很奇怪,有警告資訊。
ggplot(d, aes(Component, Freq,填充=Subtype2))
geom_bar(position = 'fill', stat = 'identity')
scale_x_discrete(expand = c(0。 03, 0.5)
scale_y_continuous('分布'。 擴展= c(0。 0)。 限制 = c(0。 100))
scale_fill_nejm()
guides(fill = guide_legend(title = 'IHC subtype')
coord_polar(theta = 'y')
主題(panel.background = element_blank(),
plot.background = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 0。 25),
axis.ticks = element_line(size = 0。 25),
軸。 title = element_text(size = 12),/span>
axis.text. y = element_text(size = 10), axis.text.
axis.text. x = element_text(size = 10))
警告資訊:
洗掉了包含6行的缺失值(position_stack)。
。
data
structure(list(Component=結構(c(11L。 10L, 9L。 8L, 11L,
10L, 9L, 8L, 11L, 10L。 9L, 8L, 11L。 10L, 9L), 。 標簽 = c("10",.
"9", "8"。 "7",/span> "6"。 "5", "4", "3"。 "2",/span> "1"。 "0")。 class = " factor"),
子型別2 =結構(c(3L。 3L, 3L。 3L, 1L, 1L。 1L, 1L。 2L, 2L,
2L, 2L,, 4L, 4L。 4L), 。 標簽 = c("HR /HER2-"。 "HR /HER2 ",
"HR-/HER2 ", "TNBC")。 class = " factor")。 Freq = c(12L。 433L,
67L, 66L, 87L。 461L, 287L, 84L。 17L, 332L, 60L。 32L, 44L,
278L, 159L)), 行。 names = c(1L。 2L, 3L。 4L, 12L。 13L, 14L,
15L, 23L, 24L。 25L, 26L。 34L, 35L。 36L), class = "data. frame")
uj5u.com熱心網友回復:
這比我想象的要棘手一些。在計算位置之前,y-scale似乎想扔掉超過限制的值。為了防止這種情況,你可以使用scales::oob_keep()來保留這些值。下面是簡化的例子。
library(ggplot2)
# d <- structure(...) #取自問題,為簡潔起見略去。
ggplot(d, aes(Component, Freq, 填充= Subtype2))
geom_col(position = "fill")
scale_y_continuous(limits = c(0。 1. 1),oob=scales。 :oob_keep)
coord_polar(theta = "y")

轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330199.html
標籤:




