我使用以下数据绘制我的图表:
transData = structure(list(Type = c("A", "B", "A",
"A", "A", "B", "B",
"B", "A", "A", "A",
"A", "A", "A", "A",
"A", "A", "B", "A",
"B", "A", "A", "B",
"A", "A", "B", "A",
"A", "A", "B", "A",
"A", "B", "B", "A",
"B", "A", "A", "B",
"B", "A", "A", "A",
"A", "B", "B", "A",
"A", "A", "A", "B",
"A", "A", "A", "A",
"A", "A", "B", "B",
"A", "A", "A", "A",
"B", "A", "A", "B",
"B", "A", "A", "C",
"A", "B", "B", "A",
"A", "A", "A", "B",
"A", "B", "B", "A",
"A", "B", "B", "B",
"A", "B", "A", "A",
"B", "A", "C", "A",
"B", "A", "C", "B",
"A", "B", "A", "A",
"A", "B", "A", "A",
"B", "A", "A", "B",
"A", "A", "A", "B",
"B", "C", "B", "B",
"A", "B", "C", "B",
"A", "B", "A", "A",
"B", "B", "B", "A",
"B", "B", "B", "A",
"A", "A", "A", "A",
"A", "A", "A", "A",
"A", "B", "A", "B",
"A", "C", "B", "B",
"B", "B", "A", "A",
"B", "A", "A", "A",
"B", "A", "A", "A",
"C", "A", "B", "A",
"A", "B", "B", "B",
"A", "A", "A", "B",
"C", "B", "A", "A",
"B", "A", "A", "A",
"B", "C", "A", "B",
"C", "B", "A", "B",
"B", "A", "B", "B",
"A", "A", "C", "C",
"A", "B", "A", "A",
"A", "A", "A", "A",
"B", "B", "A", "A",
"B", "A", "B", "B",
"B", "A", "C", "A",
"A", "A", "A", "A",
"B", "B", "A", "C",
"A", "B", "B", "B",
"B", "B", "B", "B", "B",
"B", "A", "A", "B",
"A", "B", "A", "B",
"B"), Time = c(53L, 195L, 48L, 172L, 73L, 39L, 469L,
135L, 46L, 121L, 158L, 158L, 53L, 261L, 53L, 72L, 153L, 90L,
53L, 13L, 568L, 173L, 163L, 619L, 156L, 11L, 67L, 88L, 264L,
392L, 45L, 969L, 37L, 150L, 187L, 407L, 46L, 88L, 37L, 139L,
508L, 78L, 51L, 803L, 17L, 21L, 255L, 64L, 154L, 47L, 400L, 459L,
189L, 236L, 52L, 86L, 153L, 25L, 56L, 265L, 384L, 123L, 356L,
66L, 44L, 124L, 151L, 357L, 860L, 54L, 187L, 80L, 105L, 13L,
100L, 92L, 794L, 284L, 238L, 383L, 533L, 319L, 146L, 152L, 769L,
216L, 13L, 123L, 19L, 206L, 81L, 26L, 51L, 243L, 1041L, 258L,
65L, 164L, 23L, 60L, 51L, 383L, 137L, 460L, 12L, 52L, 766L, 415L,
72L, 111L, 355L, 68L, 690L, 56L, 156L, 20L, 309L, 120L, 74L,
136L, 284L, 101L, 191L, 160L, 12L, 309L, 655L, 586L, 14L, 17L,
590L, 31L, 20L, 152L, 68L, 68L, 44L, 167L, 54L, 510L, 68L, 142L,
73L, 72L, 263L, 74L, 654L, 73L, 207L, 185L, 194L, 412L, 274L,
538L, 111L, 702L, 198L, 192L, 136L, 78L, 141L, 904L, 88L, 155L,
78L, 352L, 106L, 901L, 40L, 572L, 242L, 237L, 776L, 215L, 357L,
138L, 118L, 70L, 761L, 39L, 191L, 153L, 146L, 22L, 109L, 102L,
293L, 184L, 34L, 201L, 183L, 295L, 541L, 79L, 130L, 46L, 87L,
338L, 515L, 362L, 76L, 947L, 46L, 67L, 45L, 140L, 465L, 359L,
45L, 166L, 88L, 49L, 352L, 77L, 137L, 245L, 79L, 106L, 94L, 59L,
488L, 45L, 250L, 83L, 293L, 195L, 106L, 452L, 691L, 34L, 499L,
239L, 75L, 25L, 621L, 20L, 674L, 332L, 95L, 146L, 383L, 333L,
185L, 220L, 161L), ecd = c(0.123382007072638, 0.579233848636846,
0.0786196511057343, 0.563264580971557, 0.25540176985161, 0.205968448867862,
0.883020300954129, 0.481843067137138, 0.0563442242940052, 0.439070404900086,
0.534762525168779, 0.534762525168779, 0.123382007072638, 0.707356897514424,
0.123382007072638, 0.247948427268574, 0.520566487876686, 0.384657985094701,
0.123382007072638, 0.0339245874143578, 0.916735757432192, 0.566242533967276,
0.530245731736262, 0.933461362751899, 0.52861203702137, 0.00379752844190573,
0.221696756400061, 0.324190792033976, 0.711629244852033, 0.814633142929477,
0.0413783184717687, 0.987792084736299, 0.195825883320939, 0.508900457285717,
0.591470533493511, 0.829918194908147, 0.0563442242940052, 0.324190792033976,
0.195825883320939, 0.490893843257014, 0.894172687433377, 0.277338792913825,
0.102722458164836, 0.970008967699362, 0.0718524027278913, 0.104416209117233,
0.70075802439891, 0.19962437183804, 0.521818581749886, 0.0676046090590684,
0.822259845883637, 0.869706096343547, 0.594177763489619, 0.678296475524949,
0.112350044838497, 0.314554745266578, 0.520566487876686, 0.13253374262251,
0.27733033750534, 0.713042080506252, 0.826931862405035, 0.44684523104516,
0.804673355780782, 0.31380243358281, 0.0261247694624456, 0.449603221603695,
0.511210620421209, 0.778097754711309, 0.976692441752255, 0.135767584304834,
0.593356785279394, 0.289402886583983, 0.421889586860552, 0.0339245874143578,
0.372142603340045, 0.338259927920001, 0.968553831576454, 0.735469789005262,
0.630104906723208, 0.826161993874892, 0.920441779142075, 0.731641323438662,
0.497140488316611, 0.517512394037326, 0.982610484343107, 0.604076013860979,
0.0339245874143578, 0.44684523104516, 0.0906976376208484, 0.632831931777804,
0.294275900576978, 0.13978069273248, 0.102722458164836, 0.670274658368286,
0.992614338166867, 0.662969350780867, 0.206578568890543, 0.544851846840752,
0.117517682241808, 0.176545236121216, 0.257140144622541, 0.826161993874892,
0.466421887954519, 0.870416744217526, 0.0201585468124496, 0.112350044838497,
0.96496675183161, 0.837624013038181, 0.247948427268574, 0.410077663660513,
0.775645184259245, 0.23097747923047, 0.951760545506844, 0.147560954975381,
0.519739236380322, 0.099416130002057, 0.732309565687999, 0.455829997310084,
0.340052848937483, 0.458562460872066, 0.688681782939603, 0.2929238262752,
0.572967926707701, 0.540464628348082, 0.0201585468124496, 0.757728295629516,
0.943055109050608, 0.942483267140303, 0.0416304055443915, 0.0718524027278913,
0.924569804233431, 0.165255779363598, 0.099416130002057, 0.51320432285321,
0.23097747923047, 0.23097747923047, 0.0261247694624456, 0.550642121114702,
0.135767584304834, 0.895247119338082, 0.23097747923047, 0.480406422903166,
0.25540176985161, 0.247948427268574, 0.668190952388487, 0.261653779123873,
0.963448788746657, 0.25540176985161, 0.626978757948857, 0.562762069020079,
0.577920536717353, 0.835567018465482, 0.678048703302267, 0.906431363259505,
0.410077663660513, 0.973591354293581, 0.614397387523054, 0.600252110793388,
0.458562460872066, 0.350701751609994, 0.476438638940119, 0.982199962775588,
0.324190792033976, 0.525233391963199, 0.277338792913825, 0.771499549043497,
0.390424865907514, 0.981929239775977, 0.211095112264435, 0.936992673934714,
0.637241095586956, 0.6798954332414, 0.966176545236121, 0.647950119287322,
0.778097754711309, 0.476796103368962, 0.452475513853067, 0.237187188034043,
0.963723118052148, 0.205968448867862, 0.597536420703541, 0.520566487876686,
0.497140488316611, 0.109432111267583, 0.340819916114193, 0.381262584389435,
0.697305337109764, 0.586321201461237, 0.182803525372237, 0.621774589262449,
0.559613285020333, 0.698950932767924, 0.907581936007851, 0.354182819348407,
0.474437886675422, 0.0563442242940052, 0.319503900103213, 0.771884724665133,
0.952509809227439, 0.809817092773388, 0.346461178183199, 0.985702441583053,
0.0563442242940052, 0.221696756400061, 0.0413783184717687, 0.473765249318962,
0.872447166714607, 0.780249687495055, 0.231459358534154, 0.546454374714472,
0.324190792033976, 0.250130540040191, 0.800113365256087, 0.348723872213168,
0.486336809126727, 0.642130413455909, 0.283286238811526, 0.317886618860777,
0.348589702373902, 0.168711189319978, 0.884181316728989, 0.0413783184717687,
0.696071132468148, 0.36597098055349, 0.697305337109764, 0.608339960406761,
0.317886618860777, 0.86644896025448, 0.971344483298786, 0.182803525372237,
0.902150350480229, 0.631165050079906, 0.343059225620659, 0.13253374262251,
0.954382189591607, 0.099416130002057, 0.967721008243801, 0.781780342126191,
0.354190284428351, 0.502966819095239, 0.826161993874892, 0.749521353185968,
0.585929172095227, 0.6082374721119, 0.527745692178674)), .Names = c("Type",
"Time", "ecd"), row.names = c(92048L, 159572L, 29319L, 895L,
96262L, 125686L, 151273L, 147065L, 28209L, 95224L, 103747L, 10879L,
49632L, 69265L, 33170L, 48374L, 16205L, 143414L, 82739L, 154277L,
13742L, 117040L, 143588L, 18939L, 116302L, 144944L, 64894L, 102723L,
1421L, 135064L, 75449L, 5061L, 168170L, 160731L, 19821L, 173593L,
62523L, 50640L, 167359L, 137913L, 67097L, 27037L, 104748L, 96568L,
128256L, 178185L, 115092L, 37467L, 53973L, 2762L, 125710L, 116687L,
82651L, 43058L, 93370L, 22432L, 18723L, 178221L, 119588L, 11606L,
80362L, 59335L, 29222L, 162110L, 7119L, 31354L, 165632L, 139490L,
79415L, 89257L, 189343L, 96964L, 159220L, 130710L, 115290L, 29444L,
93645L, 13899L, 130561L, 112611L, 181065L, 121678L, 1852L, 47480L,
171098L, 121083L, 172035L, 38523L, 157838L, 27012L, 64525L, 120340L,
6908L, 185441L, 94868L, 127875L, 40124L, 189556L, 176948L, 84118L,
138852L, 92739L, 93656L, 70139L, 119493L, 20076L, 4803L, 127323L,
97064L, 101198L, 136526L, 24723L, 102465L, 101097L, 150643L,
174126L, 185593L, 163301L, 128247L, 17460L, 163927L, 195729L,
138856L, 41180L, 154046L, 29339L, 63140L, 140632L, 157913L, 168675L,
42034L, 118559L, 160614L, 118860L, 49961L, 35882L, 78742L, 26291L,
64902L, 49245L, 103381L, 101070L, 32259L, 13696L, 164332L, 101497L,
152968L, 88841L, 191957L, 121281L, 118529L, 173451L, 125052L,
44653L, 2222L, 172544L, 116888L, 104866L, 61270L, 155764L, 17674L,
98520L, 40820L, 194711L, 43838L, 155574L, 32706L, 9154L, 120867L,
156124L, 154257L, 95360L, 37296L, 54368L, 121511L, 194348L, 159059L,
43141L, 29429L, 160099L, 103555L, 8503L, 42416L, 153399L, 186559L,
77999L, 176027L, 188806L, 175228L, 92429L, 136741L, 174362L,
51964L, 161122L, 121702L, 93140L, 22541L, 190945L, 182507L, 22773L,
177446L, 111509L, 6628L, 66138L, 62548L, 89360L, 15893L, 144181L,
176730L, 11872L, 54318L, 142521L, 35141L, 152314L, 141205L, 126686L,
73151L, 188807L, 29005L, 108612L, 83108L, 49737L, 11175L, 170696L,
120640L, 8301L, 188871L, 14800L, 136572L, 132040L, 166694L, 128195L,
146465L, 179101L, 181150L, 155944L, 126596L, 3857L, 9142L, 152723L,
95394L, 151840L, 103143L, 119138L, 158685L), class = "data.frame")
我使用的代码如下:
plot = ggplot(transData, aes(x=Time, y=ecd)) +
geom_line(size=1.5, aes(color=Type, group=Type, linetype=Type)) +
scale_y_continuous("P[X<x]", lim=c(0,1)) +
scale_x_continuous("") +
geom_hline(aes(yintercept=0.5), linetype=4) +
geom_text(aes(1100, .55, label="Median"),size=7) +
geom_hline(aes(yintercept=0.95), linetype=4) +
geom_text(aes(1100, 0.90, label="95th Percentile"),size=7) +
geom_vline(aes(xintercept=30), linetype=4) +
geom_text(aes(40, .85, label="1 month"),size=7) +
geom_vline(aes(xintercept=90), linetype=4) +
geom_text(aes(190, .15, label="6 months"),size=7) +
geom_vline(aes(xintercept=365), linetype=4) +
geom_text(aes(380, .40, label="1 year"),size=7) +
geom_vline(aes(xintercept=365*2), linetype=4) +
geom_text(aes(380*2, .15, label="2 years"),size=7) +
geom_vline(aes(xintercept=365*3), linetype=4) +
geom_text(aes(380*3, .15, label="3 years"),size=7) +
theme_bw() +
opts(plot.title = theme_text(size=36, colour="black", face="bold"),
axis.text.y=theme_text(size=16, colour="black"),
axis.text.x=theme_text(size=16, colour="black"),
axis.title.y=theme_text(angle=90, size=14, vjust=0.2, hjust=0.5, face="bold"),
axis.title.x=theme_text(size=14, vjust=0.2, hjust=0.5, face="bold"),
legend.position = "top",
legend.title = theme_blank(),
strip.text.y=theme_text(size=12, colour="black", face="bold"),
strip.text.x=theme_text(size=12, colour="black", face="bold"),
legend.text = theme_text(size=12, face="bold"),
legend.key.size = unit(1.5, "lines"),
legend.key.width = unit(4, "line"),
legend.direction = "horizontal")
print(plot)
有谁知道为什么我从geom_text
这么黑的文字?当我将其插入到pdf文件中时,它变得非常难看。关于如何解决这个问题的任何建议?
答案 0 :(得分:1)
data2.labels <- data.frame(
time = c(7, 15),
value = c(.9, .6),
label = c("correct color", "another correct color!"),
type = c("NA*", "MVH")
)
ggplot(data2, aes(x=time, y=value, group=type, col=type))+
geom_line()+
geom_point()+
theme_bw() +
geom_text(data = data2.labels, aes(x = time, y = value, label = label))