R语言学习——3D饼图

clinical <- read.table('/Users/zhangzhishuai/Downloads/30 R饼图/30.pie/30.clinical.tsv', sep = '\t', header = T,row.names = 1)
clinical
stage=clinical$tumor_stage
length(stage)
table(stage)
prob=round( # 四舍五入
  prop.table(table(stage)), #计算一组数值里每个数所占百分比
  3 #保留两位小数
)
prob=sort(prob,decreasing = T) #从大到小排列
library(RColorBrewer)
brewer.pal.info #查看配色方案
display.brewer.all() #所有配色方案展示
#测试
barplot( 
  rep(1,19),
  col = brewer.pal(9,'YlOrRd')
)
barplot(rep(1,9),col = rainbow(9))

# 饼图
pie(
  prob,
  labels = names(prob), # 添加每个饼标签
  clockwise = TRUE, # 顺时针画图
  radius = 1, # 半径
  # init.angle=0, #旋转角度
  col = brewer.pal(6, # RColorBrewer前六种颜色
                   'Set1'), # 控制每个类型颜色
  # col=rainbow(6), # 另一个添加颜色方法
  border = 'white', #每个类中间的颜色
  main = 'Percentage of ---'
)

# 显示百分比
pielabels <- sprintf(
  '%s = %.1f%s', # %s指的prob第一个字符串(每个分类的名字) %.1f(控制数字输出格式) 显示小数点后面1位
  names(prob),
  100*prob, # 计算要显示的数字
  '%' # 显示百分号字符
) 

pie(
  prob,
  labels = pielabels, # 添加每个饼标签
  clockwise = TRUE, # 顺时针画图
  radius = 1, # 半径
  # init.angle=0, #旋转角度
  col = brewer.pal(6, # RColorBrewer前六种颜色
                   'Set1'), # 控制每个类型颜色
  # col=rainbow(6), # 另一个添加颜色方法
  border = 'white', #每个类中间的颜色
  main = 'Percentage of ---'
)
# 显示图注
pie(
  prob,
  labels = NA, # 不显示label
  clockwise = TRUE, # 顺时针画图
  radius = 0.5, # 半径
  # init.angle=0, #旋转角度
  col = brewer.pal(6, # RColorBrewer前六种颜色
                   'Set1'), # 控制每个类型颜色
  # col=rainbow(6), # 另一个添加颜色方法
  border = 'white', #每个类中间的颜色
  main = 'Percentage of ---'
)
legend('bottomright',
       legend = pielabels,
       bty='n',
       fill = brewer.pal(6,'Set1')
       
       )

# 3D饼图
par(mar=c(5,4,4,2)) #下左上右边界
library(plotrix)
pdf(file = '/Users/zhangzhishuai/Downloads/30 R饼图/30.pie/3d.pdf')
pie3D(
  prob,
  labels = names(prob),
  start = 0, #控制起始角度,旋转
  col = brewer.pal(6,'Set1'),
  explode = 0.1, # 控制饼的大小,间隔
  main = '3Dplot'
)

legend('topright',
       legend = pielabels,
       bty='n',
       fill = brewer.pal(6,'Set1')
)
dev.off()

30.clinical.tsv:

case_id	submitter_id	project_id	gender	year_of_birth	race	ethnicity	year_of_death	classification_of_tumor	last_known_disease_status	primary_diagnosis	tumor_stage	age_at_diagnosis	vital_status	morphology	days_to_death	days_to_last_known_disease_status	days_to_recurrence	tumor_grade	tissue_or_organ_of_origin	days_to_birth	progression_or_recurrence	prior_malignancy	site_of_resection_or_biopsy	days_to_last_follow_up	therapeutic_agents	treatment_intent_type	treatment_or_therapy
6e534dd3-81ac-4575-ab1e-02c21e10916d	TCGA-W5-AA2X	TCGA-CHOL	male	1943	white	not hispanic or latino	2010	not reported	not reported	C24.0	stage ivb	24797	dead	8160/3	271.0	--	--	not reported	C24.0	-24797.0	not reported	not reported	C24.0	--	--	--	--
3824cd6d-c85c-4b21-819a-932d1afef976	TCGA-3X-AAVB	TCGA-CHOL	female	1942	white	not hispanic or latino	--	not reported	not reported	C24.0	stage ivb	25819	alive	8160/3	--	--	--	not reported	C24.0	-25819.0	not reported	not reported	C24.0	402.0	--	--	--
adc9a685-5b4a-4c29-881a-da1895c47520	TCGA-W5-AA34	TCGA-CHOL	female	1937	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	27535	dead	8160/3	555.0	--	--	not reported	C22.1	-27535.0	not reported	not reported	C22.1	168.0	--	--	--
2d6e20b2-82c7-4c12-92d0-93282b0a9031	TCGA-W5-AA31	TCGA-CHOL	male	1939	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	26139	alive	8160/3	--	--	--	not reported	C22.1	-26139.0	not reported	not reported	C22.1	10.0	--	--	--
ff4131c9-537c-46cc-b495-9af60d431f5e	TCGA-3X-AAVC	TCGA-CHOL	female	1940	white	not hispanic or latino	--	not reported	not reported	C24.0	stage i	26493	alive	8160/3	--	--	--	not reported	C24.0	-26493.0	not reported	not reported	C24.0	709.0	--	--	--
f2d42e03-ca8d-4b57-ae39-0cc8f37b1b67	TCGA-W5-AA36	TCGA-CHOL	female	1957	white	not hispanic or latino	2011	not reported	not reported	C22.1	stage iv	18882	dead	8160/3	1402.0	--	--	not reported	C22.1	-18882.0	not reported	not reported	C22.1	--	--	--	--
f47dbd99-920b-4b39-a1b0-6c152ad24884	TCGA-W5-AA2Q	TCGA-CHOL	male	1938	white	not hispanic or latino	--	not reported	not reported	C22.1	stage ii	25069	alive	8160/3	--	--	--	not reported	C22.1	-25069.0	not reported	not reported	C22.1	50.0	--	--	--
47a9ef9b-04f0-4e8d-bfdb-0846ba30d08b	TCGA-ZH-A8Y2	TCGA-CHOL	female	1952	black or african american	not hispanic or latino	2012	not reported	not reported	C22.1	stage i	21743	dead	8160/3	701.0	--	--	not reported	C22.1	-21743.0	not reported	not reported	C22.1	--	--	--	--
20ec1cd9-7bdb-4eb9-9d20-65795580f1f5	TCGA-W5-AA2Z	TCGA-CHOL	female	1981	white	not hispanic or latino	--	not reported	not reported	C22.1	stage ii	10659	alive	8160/3	--	--	--	not reported	C22.1	-10659.0	not reported	not reported	C22.1	1614.0	--	--	--
9d9109f5-5917-4126-8e34-8a7e4632e913	TCGA-ZH-A8Y5	TCGA-CHOL	male	1943	white	not hispanic or latino	--	not reported	not reported	C22.1	stage ivb	25268	alive	8160/3	--	--	--	not reported	C22.1	-25268.0	not reported	not reported	C22.1	1229.0	--	--	--
22bf93b3-c8dc-4669-862f-3e4ae478849b	TCGA-W5-AA2G	TCGA-CHOL	female	1946	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	22933	alive	8160/3	--	--	--	not reported	C22.1	-22933.0	not reported	not reported	C22.1	1976.0	--	--	--
3c8ca064-a4a7-416f-a069-4324d4a72038	TCGA-W5-AA2I	TCGA-CHOL	male	1939	white	not hispanic or latino	2010	not reported	not reported	C22.1	stage i	24388	dead	8160/3	1939.0	--	--	not reported	C22.1	-24388.0	not reported	not reported	C22.1	--	--	--	--
5fb3affa-3661-48e8-a1cc-b533c862e8c5	TCGA-W5-AA33	TCGA-CHOL	male	1951	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	22090	alive	8160/3	--	--	--	not reported	C22.1	-22090.0	not reported	not reported	C22.1	1449.0	--	--	--
b10c64c2-7fd2-4210-b975-034affb14b57	TCGA-4G-AAZT	TCGA-CHOL	male	1951	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	22777	alive	8160/3	--	--	--	not reported	C22.1	-22777.0	not reported	not reported	C22.1	420.0	--	--	--
8944fe2a-e32f-4898-a2c5-fb6751f602a4	TCGA-W5-AA2T	TCGA-CHOL	female	1944	white	not hispanic or latino	2011	not reported	not reported	C22.1	stage ii	23560	dead	8160/3	1220.0	--	--	not reported	C22.1	-23560.0	not reported	not reported	C22.1	--	--	--	--
779ce92d-1abd-44fc-9021-eda4d7f08fff	TCGA-YR-A95A	TCGA-CHOL	male	1957	white	not reported	2009	not reported	not reported	C24.0	stage iv	19292	dead	8160/3	26.0	--	--	not reported	C24.0	-19292.0	not reported	not reported	C24.0	--	--	--	--
32e9558c-946b-4288-91e1-504e47c308ac	TCGA-W5-AA39	TCGA-CHOL	male	1929	white	not hispanic or latino	2010	not reported	not reported	C22.1	stage ii	29594	dead	8160/3	170.0	--	--	not reported	C22.1	-29594.0	not reported	not reported	C22.1	--	--	--	--
7047dc12-e2ed-40b7-86fd-c5c53a2766fd	TCGA-W6-AA0S	TCGA-CHOL	female	1967	white	hispanic or latino	--	not reported	not reported	C22.1	stage i	16951	alive	8160/3	--	--	--	not reported	C22.1	-16951.0	not reported	not reported	C22.1	808.0	--	--	--
180a2b9c-9cac-4d96-86e8-cd6b3b9386b5	TCGA-W5-AA2O	TCGA-CHOL	male	1949	white	not hispanic or latino	2007	not reported	not reported	C22.1	stage i	21118	dead	8160/3	640.0	--	--	not reported	C22.1	-21118.0	not reported	not reported	C22.1	--	--	--	--
e76cf9a0-061e-4a7d-ba28-5a40b8da54b8	TCGA-ZU-A8S4	TCGA-CHOL	male	1960	white	not hispanic or latino	2012	not reported	not reported	C22.1	stage i	19264	dead	8160/3	98.0	--	--	not reported	C22.1	-19264.0	not reported	not reported	C22.1	--	--	--	--
0775583e-c0a0-4f18-9ca2-8f89cedce3d6	TCGA-4G-AAZO	TCGA-CHOL	female	1941	white	not hispanic or latino	--	not reported	not reported	C22.1	stage ii	25989	alive	8160/3	--	--	--	not reported	C22.1	-25989.0	not reported	not reported	C22.1	1177.0	--	--	--
5166d82f-7b22-4101-bea9-6056e5a74c48	TCGA-ZH-A8Y6	TCGA-CHOL	female	1972	black or african american	not hispanic or latino	--	not reported	not reported	C22.1	stage i	14976	alive	8160/3	--	--	--	not reported	C22.1	-14976.0	not reported	not reported	C22.1	519.0	--	--	--
5cf3911a-f3ea-4c0e-851d-5bb57ca7190f	TCGA-ZH-A8Y8	TCGA-CHOL	male	1940	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	26744	alive	8160/3	--	--	--	not reported	C22.1	-26744.0	not reported	not reported	C22.1	602.0	--	--	--
aaacf22c-2362-4613-b024-88fb7dd1cca1	TCGA-W5-AA2U	TCGA-CHOL	female	1932	white	not hispanic or latino	2011	not reported	not reported	C22.1	stage i	28552	dead	8160/3	627.0	--	--	not reported	C22.1	-28552.0	not reported	not reported	C22.1	--	--	--	--
b4f7f9e4-5fc5-4461-8e0b-0b6c384863c6	TCGA-W5-AA30	TCGA-CHOL	male	1928	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	30039	alive	8160/3	--	--	--	not reported	C22.1	-30039.0	not reported	not reported	C22.1	1153.0	--	--	--
95b69517-4971-450e-9ed0-43bc8b2c0534	TCGA-ZH-A8Y4	TCGA-CHOL	male	1952	white	not hispanic or latino	2012	not reported	not reported	C22.1	stage i	21503	dead	8160/3	741.0	--	--	not reported	C22.1	-21503.0	not reported	not reported	C22.1	--	--	--	--
fe57b639-db7a-460f-adfe-552f1e034e46	TCGA-3X-AAVA	TCGA-CHOL	female	1962	white	not hispanic or latino	2013	not reported	not reported	C22.1	stage ii	18303	dead	8160/3	445.0	--	--	not reported	C22.1	-18303.0	not reported	not reported	C22.1	--	--	--	--
20bf79af-3b0f-477d-b619-5597d42f5d5e	TCGA-W5-AA2R	TCGA-CHOL	female	1929	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	28367	alive	8160/3	--	--	--	not reported	C22.1	-28367.0	not reported	not reported	C22.1	1542.0	--	--	--
b16e9c3f-c7df-46c2-bee3-ecaebbab025f	TCGA-ZH-A8Y1	TCGA-CHOL	female	1938	white	not hispanic or latino	2013	not reported	not reported	C22.1	stage iva	27279	dead	8160/3	385.0	--	--	not reported	C22.1	-27279.0	not reported	not reported	C22.1	--	--	--	--
41b97b11-acaa-4fbc-b3b0-0abc1bcac13b	TCGA-3X-AAV9	TCGA-CHOL	male	1938	asian	not hispanic or latino	2010	not reported	not reported	C22.1	stage i	26349	dead	8160/3	339.0	--	--	not reported	C22.1	-26349.0	not reported	not reported	C22.1	--	--	--	--
bc15cec4-1f82-47fe-ae69-3853194fab7e	TCGA-W5-AA2H	TCGA-CHOL	female	1942	white	not hispanic or latino	--	not reported	not reported	C22.1	stage iii	25775	alive	8160/3	--	--	--	not reported	C22.1	-25775.0	not reported	not reported	C22.1	1077.0	--	--	--
1d136284-bdf5-498e-9506-4893801a337c	TCGA-W5-AA2W	TCGA-CHOL	female	1979	white	not hispanic or latino	2012	not reported	not reported	C22.1	stage iva	11438	dead	8160/3	924.0	--	--	not reported	C22.1	-11438.0	not reported	not reported	C22.1	--	--	--	--
48d17b17-348c-405a-ae92-f190372a3aac	TCGA-W5-AA38	TCGA-CHOL	female	1956	white	not hispanic or latino	--	not reported	not reported	C22.1	stage i	20285	alive	8160/3	--	--	--	not reported	C22.1	-20285.0	not reported	not reported	C22.1	1471.0	--	--	--
dcc87c59-fd8c-4511-9983-96d5b9784cb0	TCGA-3X-AAVE	TCGA-CHOL	male	1953	asian	not hispanic or latino	--	not reported	not reported	C22.1	stage ii	21943	alive	8160/3	--	--	--	not reported	C22.1	-21943.0	not reported	not reported	C22.1	650.0	--	--	--
4290b3b3-94f6-43e4-8309-430dd973ae2d	TCGA-WD-A7RX	TCGA-CHOL	female	1942	white	hispanic or latino	2013	not reported	not reported	C22.0	stage ii	26006	dead	8160/3	21.0	--	--	not reported	C22.0	-26006.0	not reported	not reported	C22.0	--	--	--	--
ccb028ae-777c-4af6-b92e-40848f1cf774	TCGA-ZD-A8I3	TCGA-CHOL	female	1940	asian	not hispanic or latino	--	not reported	not reported	C22.1	stage ii	26754	dead	8160/3	169.0	--	--	not reported	C22.1	-26754.0	not reported	not reported	C22.1	0.0	--	--	--
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值