- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是一个有更新的转贴,因为回复原贴的人能够解决部分问题,但我们发现了一个需要解决的新问题,我还没有找到其他帖子解决这个问题。如果不允许这样做,请告诉我!
所以我有一个包含四列和一大堆行的标题。我会把前几行放在帖子的末尾。第一列称为 id,每一行都有一个唯一的 id。下一列是 doy.series
,第三列称为 smooth.series
doy.series
和 smooth 中的每个条目。 series
列是列表。最后一列名为 doy
,它是一个整数。
所以我想要的是针对每行的 smooth.series
绘制 doy.series
,但将所有这些绘制为同一图上的线。我还希望线条由 doy
着色。我希望最高的 doy
值是红色的,逐渐过渡到最低的 doy
值,我希望它是蓝色的。
问题在于两个列表的长度逐行略有不同(因此给定行的 doy.series
和 smooth.series
列表具有相同的长度元素的数量,但元素的数量因行而异)。所以如果我尝试这样做:
library(tidyverse)
df2 <- df %>%
unnest()
ggplot(df2, aes(x = doy.series, y = smooth.series, color = doy, group = doy)) +
geom_line() +
scale_color_gradient(low = "blue", high = "red")
我收到错误:所有嵌套列必须具有相同数量的元素。
关于如何解决这个问题的任何想法?
数据样本:
df=structure(list(id = c("1", "2", "3"), doy = c(152, 158, 142),
smooth.series = list(c(0.356716711457841, 0.370050893258325,
0.383236999766461, 0.396376974233949, 0.40957275991249, 0.422784291482468,
0.435895856103075, 0.448895925744217, 0.461772972375802,
0.474515467967738, 0.48722268616777, 0.499933470515835, 0.512545647820125,
0.524957044888832, 0.537065488530148, 0.549189274496968,
0.561532939869938, 0.573823673448877, 0.5857886640336, 0.597155100423927,
0.608751798005646, 0.621116663488914, 0.633540522660091,
0.645314201305544, 0.655728525211634, 0.665571086939856,
0.675708836320647, 0.685551635043781, 0.694509344799033,
0.701991827276177, 0.70938842013153, 0.717660871422796, 0.725577658441836,
0.731907258480512, 0.735418148830686, 0.737609381488737,
0.740068708326791, 0.741697656450321, 0.741397752964802,
0.738070524975708, 0.730787113459408, 0.720275348839784,
0.707921792393576, 0.695113005397529, 0.683235549128384,
0.66854065601544, 0.648565682783239, 0.626626377151392, 0.606038486839507,
0.590117759567193, 0.575248354822936, 0.557183338977548,
0.538291820074129, 0.520942906155777, 0.507505705265592,
0.497170423227522, 0.487542218972326, 0.478612630203321,
0.470373194623822, 0.462815449937146, 0.458831683827816,
0.459466542404155, 0.461940101005184, 0.463472434969922,
0.461283619637389, 0.458826926942516, 0.459760482491641,
0.461611642130895, 0.461907761706409, 0.458176197064313,
0.45041527548862, 0.440794234319326, 0.430096794486539, 0.419106676920368,
0.408607602550923, 0.396242242656226, 0.380503346606902,
0.363449752471964, 0.347140298320423, 0.333633822221291,
0.321253095838767, 0.307606088569194, 0.293679435079791,
0.28045977003778, 0.268933728110384, 0.258699817638372, 0.248739536036072,
0.239114001581039, 0.22988433255083, 0.221111647222998, 0.213576575535607,
0.207511807976447, 0.202156553647666, 0.196750021651411,
0.19053142108983, 0.183900129705502, 0.177683584689661, 0.17176308431744,
0.166019926863971, 0.160335410604389, 0.153743267353215,
0.146014563103421, 0.138136597397814, 0.131096669779199,
0.125882079790385, 0.121448622919517, 0.116554575980903,
0.111890960506595, 0.10814879802864, 0.106019110079089, 0.105661169696536,
0.106498694582266, 0.108119373262358, 0.110110894262892,
0.11206094610995, 0.11540233539241, 0.120997725074791, 0.127579588246629,
0.133880397997461, 0.138632627416822, 0.143475963087052,
0.150098990228934, 0.157307529889666, 0.163907403116449,
0.168704430956481, 0.172368187413333, 0.176173416587563,
0.179833694671856, 0.183062597858895, 0.185573702341366,
0.187052218702838, 0.187638597324987, 0.187729274097655,
0.187720684910687, 0.188009265653923, 0.188094043051569,
0.187473296399738, 0.186542340446139, 0.185696489938482,
0.185331059624476, 0.18519846898834, 0.184852749545972, 0.184391634092598,
0.183912855423446, 0.183514146333744, 0.183117312589153,
0.182606699408324, 0.182023848765966, 0.181410302636787,
0.180807602995498, 0.180212334083628, 0.179591966640683,
0.178944372388341, 0.178267423048277, 0.177558990342169,
0.176816945991692, 0.176039161718523, 0.175223509244339,
0.174367860290815), c(0.774610362619149, 0.746412269781788,
0.719913789191898, 0.695420287796062, 0.673237132540861,
0.653273968452586, 0.635200894750251, 0.618963959669522,
0.604509211446066, 0.59178269831555, 0.581143108860635, 0.572741206185169,
0.566211150306591, 0.561187101242345, 0.557303219009872,
0.555232501533965, 0.555534753213423, 0.557674343776691,
0.561115642952215, 0.565323020468442, 0.573372729704498,
0.586895414376992, 0.603187029720595, 0.619543530969977,
0.63326087335981, 0.649100787927623, 0.670935206211495, 0.694725384196925,
0.716432577869408, 0.732018043214443, 0.745048344614319,
0.760240534670835, 0.775281601698759, 0.787858534012854,
0.795658319927888, 0.799986340749408, 0.803308852568436,
0.805054155877942, 0.804650551170897, 0.801526338940272,
0.794278541385548, 0.783000246619136, 0.769363854003397,
0.755041762900692, 0.741706372673384, 0.725475019829043,
0.703589930868272, 0.679410840142977, 0.656297482005064,
0.637609590806439, 0.619522671663228, 0.59768917697572, 0.574684262022063,
0.553083082080407, 0.535460792428901, 0.520724989583801,
0.506208924554847, 0.492126234360422, 0.478690556018906,
0.466115526548682, 0.456163205377972, 0.449307080301381,
0.443827930886861, 0.438006536702364, 0.430123677315843,
0.422161025148951, 0.416341337462143, 0.411307021081574,
0.405700482833399, 0.398164129543771, 0.388509330252805,
0.377833000710694, 0.366705867808713, 0.355698658438137,
0.34538209949024, 0.334476225402477, 0.322019919293152, 0.309062181074817,
0.296652010660021, 0.285838407961315, 0.276447235011443,
0.267512949813937, 0.258897446237528, 0.250462618150946,
0.242070359422922, 0.234129641095434, 0.226902750204945,
0.220031554611916, 0.21315792217681, 0.205923720760086, 0.19852372751621,
0.191343478746417, 0.184310981031329, 0.177354240951568,
0.170401265087756, 0.163192040497278, 0.155702671847874,
0.148215342135701, 0.141012234356916, 0.134375531507676,
0.127758694427545, 0.120727232121655, 0.113731399834516,
0.107221452810637, 0.101647646294526, 0.0965005694542742,
0.091209569652388, 0.0861330394250022, 0.0816293713082512,
0.0780569578382695, 0.075371315752509, 0.0732346851768886,
0.0715655437302434, 0.0702823690314086, 0.0693036386992192,
0.0691863250953481, 0.0701883842483067, 0.0717797692771877,
0.073430433301084, 0.0746103294390886, 0.0761784204310707,
0.0788956524181342, 0.0820849536212236, 0.0850692522612836,
0.0871714765592586, 0.0890972731947091, 0.0916871981841642,
0.094466543754022, 0.0969606021306803, 0.0986946655405372,
0.0998521594454551, 0.100914181761071, 0.101852533394445,
0.102639015252636, 0.103245428242704, 0.103462264899288,
0.103250578499722, 0.102838011065113, 0.102452204616565,
0.102320801175184, 0.102287042959656, 0.102088178523127,
0.101792859388387, 0.10146973707823, 0.101187463115447, 0.100889974984667,
0.100495657145597, 0.100034831583652, 0.0995378202842451,
0.0990349452327908, 0.0985243275768939, 0.097982837008049,
0.0974089183275044, 0.0968010163365085, 0.0961575758363094,
0.0954770416281557, 0.0947578585132956, 0.0939984712929773,
0.0931973247684494), c(0.754994105046569, 0.759262980856892,
0.763248462599852, 0.767062652758686, 0.77081765381663, 0.774472838830307,
0.777902459086919, 0.781090934415562, 0.784022684645335,
0.786682129605334, 0.789179136777192, 0.791558707699299,
0.793707963285894, 0.795514024451214, 0.796864012109498,
0.798059444416928, 0.799307737538445, 0.800354859401417,
0.800946777933214, 0.800829461061205, 0.800535183022801,
0.800489794522664, 0.800279628189041, 0.799491016650182,
0.797710292534332, 0.793727807721641, 0.787531875152631,
0.780505769046113, 0.774032763620899, 0.7694961330958, 0.766814565429895,
0.764644322900798, 0.76247504120512, 0.759796356039472, 0.756097903100465,
0.753105409945246, 0.751812834849642, 0.750612159588286,
0.747895365935809, 0.742054435666847, 0.734349211270437,
0.726724708968583, 0.718600671135361, 0.709396840144846,
0.698532958371117, 0.685958066059214, 0.672217339551, 0.657624725365782,
0.642494170022865, 0.627139620041553, 0.608952937377657,
0.586693889874402, 0.562728282882226, 0.539421921751564,
0.519140611832852, 0.498827185487661, 0.475313450129851,
0.450798673688293, 0.427482124091856, 0.40756306926941, 0.391594783774196,
0.377888811456193, 0.365281824189383, 0.352610493847746,
0.338711492305265, 0.324742577633052, 0.312133619351959,
0.300129456510569, 0.287974928157469, 0.274914873341241,
0.260271155053797, 0.244483391182105, 0.228473053117332,
0.21316161225065, 0.199470539973226, 0.18615371420193, 0.171962954821233,
0.157816646173702, 0.144633172601908, 0.13333091844842, 0.12330701757161,
0.113524600030087, 0.104251044466771, 0.0957537295245833,
0.0883000338464436, 0.0824702507214148, 0.0782344478172879,
0.0749446653450757, 0.0719529435157916, 0.0686113225404485,
0.0661995394292459, 0.0657367472597934, 0.0661841103442199,
0.0665027929946539, 0.0656539595232242, 0.0644681965998428,
0.0641406846621584, 0.0641794786739045, 0.0640926335988149,
0.0633882044006231, 0.0619833956742033, 0.0602788637336122,
0.058507841121357, 0.0569035603799449, 0.0556992540518834,
0.0546528395507013, 0.0534742168963767, 0.0523245925410911,
0.0513651729370255, 0.0507571645363614, 0.0504376622860656,
0.050241048436331, 0.0501744603941783, 0.0502450355666279,
0.0504599113607003, 0.0510283221178971, 0.052012828131863,
0.0532005557378333, 0.0543786312710432, 0.055334181066728,
0.0564245098836434, 0.057962991953209, 0.0596708578196554,
0.0612693380272137, 0.0624796631201147, 0.0635479377810315,
0.0648035693895804, 0.0660927425354069, 0.0672616418081562,
0.0681564517974736, 0.0687850088878122, 0.0692835297177245,
0.0696907692580061, 0.0700454824794523, 0.0703864243528584,
0.0706277104270338, 0.0707098566767007, 0.0707112187115236,
0.0707101521411668, 0.0707850125752948, 0.0708833573425856,
0.0709155836751044, 0.0709043070375961, 0.0708721428948058,
0.0708417067114787, 0.070795102344694, 0.0707055967085618,
0.0705825498533734, 0.0704353218294197, 0.0702732726869918,
0.0700959115439309, 0.0698961835839182, 0.069673602956005,
0.0694276838092427, 0.0691579402926828, 0.0688638865553766,
0.0685450367463756, 0.0682009050147312, 0.0678310055094947
)), doy.series = list(c(55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78,
79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130,
131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166,
167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178,
179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190,
191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202,
203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213), c(55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85,
86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112,
113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172,
173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184,
185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196,
197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213), c(55, 56, 57, 58, 59, 60, 61, 62,
63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92,
93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105,
106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117,
118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165,
166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177,
178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201,
202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213
)), year = c("2000", "2000", "2000"), geometry = structure(list(
structure(c(-164.047259999849, -164.044659999559, -164.044719999628,
-164.038089999654, -164.028189999968, -164.019179999957,
-164.005899999985, -164.004819999643, -164.006060000169,
-164.01439999986, -164.020739999951, 62.9589599997043,
62.9570600002189, 62.9551799998571, 62.9500200002229,
62.9453699998257, 62.9321099998767, 62.9228599995894,
62.9198900002234, 62.9182900001834, 62.9161899995689,
62.9119300000695), .Dim = c(11L, 2L), class = c("XY",
"LINESTRING", "sfg")), structure(c(-163.950299999945,
-163.929679999632, -163.91427000036, -163.903839999616,
-163.892950000142, -163.874760000374, -163.857260000049,
-163.83827000026, -163.831219999803, -163.826049999708,
-163.831939999731, -163.830590000428, -163.822, -163.815322687912,
62.7265500001824, 62.7286899999436, 62.7327399996513,
62.7292899997337, 62.7222099996918, 62.7222000001299,
62.7196300003243, 62.7251300003493, 62.7253400001409,
62.7224699999905, 62.7144400002059, 62.7114699999406,
62.7062799998222, 62.7052201090963), .Dim = c(14L, 2L
), class = c("XY", "LINESTRING", "sfg")), structure(c(-163.815322687912,
-163.798689999744, -163.782269999761, -163.768690000343,
-163.762120000438, -163.757980000177, -163.754040000146,
-163.750479999652, -163.741150000172, -163.731440000256,
-163.727959999854, -163.716170000245, -163.707080000142,
-163.69419999973, -163.687290000333, -163.670841577631,
62.7052201090963, 62.7025800000671, 62.7027099997667,
62.7047399998511, 62.7076500000475, 62.7154200004327,
62.7186199996133, 62.7195300002094, 62.718240000076,
62.7119499995929, 62.7111100004263, 62.7123500000526,
62.71900000005, 62.7184800003518, 62.7155900001783, 62.7051667771758
), .Dim = c(16L, 2L), class = c("XY", "LINESTRING", "sfg"
))), class = c("sfc_LINESTRING", "sfc"), precision = 0, bbox = structure(c(-164.047259999849,
62.7025800000671, -163.670841577631, 62.9589599997043), .Names = c("xmin",
"ymin", "xmax", "ymax"), class = "bbox"), crs = structure(list(
epsg = 4326L, proj4string = "+proj=longlat +datum=WGS84 +no_defs"), .Names = c("epsg",
"proj4string"), class = "crs"), n_empty = 0L)), .Names = c("id",
"doy", "smooth.series", "doy.series", "year", "geometry"), row.names = c(NA,
3L), class = c("sf", "data.frame"), sf_column = "geometry", agr = structure(c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), .Names = c("id",
"doy", "smooth.series", "doy.series", "year"), .Label = c("constant",
"aggregate", "identity"), class = "factor"))
最佳答案
对于你给出的小例子,我只添加了select(-geometry)
:
library(tidyverse)
df3 <- df %>%
select(-geometry) %>%
unnest()
df3 %>%
ggplot(aes(x = doy.series, y = smooth.series, color = doy, group = doy)) +
geom_line() +
scale_color_gradient(low = "blue", high = "red")
关于r - 使用 unnest() 绘制存储在 tibble 中的多个不同长度的时间序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950181/
这个问题在这里已经有了答案: Combine a list of data frames into one data frame by row (9 个回答) 去年关闭。 我有一个很大的列表(200.
我想创建一个存储其他任意小标题的小标题列。 我通过以下代码设法做到了这一点,首先使用 nest()在每个内部 tibble 上然后使用 unnest()在外层 library(tibble) libr
我已尽我所能进行搜索,但仍在为我的问题而苦苦挣扎。我正在尝试根据另一个 tibble 的值对 tibble 中的列进行子集化。 更具体地说,我有一些社会经济指标: cname year ccod
我已尽我所能进行搜索,但仍在为我的问题而苦苦挣扎。我正在尝试根据另一个 tibble 的值对 tibble 中的列进行子集化。 更具体地说,我有一些社会经济指标: cname year ccod
我有两个问题,第一个是这个。 input_data # A tibble: 7 × 3 #> Genes Sample1 Sample2 #> #> 1 Ncr1
我有两个 tibbles,ranges 和 sites。第一个包含一组坐标(区域、开始、结束以及其他字符变量),另一个包含一个站点(区域、站点)。我需要获取第二个小标题中第一个小标题中给定范围(行)内
我正在使用 rtweet 包的 get_friends 函数来获取一组焦点用户的 friend 的 user_id 列表谁是从 Twitter 话语的参与者中抽样的。该函数返回一个 tibbles 列
我正在使用 rtweet 包的 get_friends 函数来获取一组焦点用户的 friend 的 user_id 列表谁是从 Twitter 话语的参与者中抽样的。该函数返回一个 tibbles 列
我想在以下代码中生成一个 tibble 列表。 tbl = tibble(id=1:10, a = rnorm(10), b = rnorm(10)) tbl_list = c("a", "b")
我有一个数据框,我需要添加一列以包含对应于现有数据框每一行的 3 个物种。希望下面的例子能说明问题: Site Year Trt A 2016 bowl A
我想用 df 中的 NA 替换 de 列,使用 df2 中的估算值来获得 df3 .我可以使用 left_join 和 coalesce 来做到这一点,但我认为这种方法不能很好地概括。有没有更好的办法
我想用 df 中的 NA 替换 de 列,使用 df2 中的估算值来获得 df3 .我可以使用 left_join 和 coalesce 来做到这一点,但我认为这种方法不能很好地概括。有没有更好的办法
假设我有一个嵌套的 tibble,格式如下: # A tibble: 3 x 3 AccountNumber Tibble1 Tibble2
在之前版本的 tidyr 中,我能够使用 tibble::add_row 将行添加到嵌套 tibble。更新到版本 1.0.0 后出现以下错误: Error: levels.vctrs_list_of
我编写了一个函数,其中一部分将矩阵转换为小标题。这在 tibble 1.4.2 中没有问题,但在 2.0.1 中会导致错误。 导致错误的代码如下 library(tibble) library(mag
我有这个列表列表: regions unnest(country) 在 base R 中,命名列表,并使用 stack : setNames(regions, seq_along(regions
我有一个问题: df % filter(! (x %>% map_lgl(~ sum(str_extract(df$x, .x) == .x, na.rm = TRUE) > 1))) #> # A
为了简化我的数据分析,我需要针对不同的变量和不同的数据组处理不同的统计测试(在该示例中为 shapiro 测试)。目的是不要写 150 次相同的代码。为此,我从我的数据集中创建了一个 tibble,其
我正在尝试通过对多个步骤进行采样来模拟一些数据。 第一步(创建 x)工作正常。 在第二步中,我想根据 x 的值从不同的向量中采样来创建变量 y。 我的代码运行没有错误,但在我试图实现的目标上失败了,因
我有一个像这样的嵌套列表: > ex ex [[1]] [[1]][[1]] [1] "This" "is" "an" "example" "." [[1]][[
我是一名优秀的程序员,十分优秀!