Put a title of plot inside a for loop - r

I have a code with a nested for loop that runs perfect and gives me 4X4 plots in a page. I need to insert the title in each plot. Below is my code.
What I wanted to do is create a vector and assign my titles inside it, as shown in code and then read it inside loop. For that, I need to convert the index i into number and use the position of second vector.
This is my approach which may not be that good so either you can use mine or give your own idea. You can play with any random datasets and use simple plot/histogram. The vectors represent the day of week and time of day respectively.
#set dimension
par(mfcol=c(4,4))
#vector definition
days<-c(1,2,3,4)
hours<-c(8,14,18,22)
#Title vector
D1<-c("Monday (7-8 am)","Monday (1-2 pm)","Monday (5-6 pm)",
"Monday (9-10 pm)")
D2<-c("Wednesday (7-8 am)","Wednesday (1-2 pm)","Wednesday (5-6 pm)",
"Wednesday (9-10 pm)")
D3<-c("Friday (7-8 am)","Friday (1-2 pm)","Friday (5-6 pm)",
"Friday (9-10 pm)")
D4<-c("Saturday (7-8 am)","Saturday (1-2 pm)","Saturday (5-6 pm)",
"Saturday (9-10 pm)")
#Loop
for (i in days)
{
for (j in hours)
{
# set positioning of the histogram
par("plt" = c(0.2,0.95,0.35,0.84))
# plot the histogram
hist(path$TT[path$days==i & path$hours==j], breaks = seq(0,60,by=3), xlab="Travel Time",
ylab="Number of paths",col="blue", **main=D??**, mgp=c(2.5,1,0))
}
}
here is data sample-> dput(path)
structure(list(days = c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L,
1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L,
2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L,
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L,
4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L,
5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L,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 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L), TT = c(34.82720833,
34.13870083, 30.59218805, 35.1616205, 34.87982204, 30.74262596,
35.19981237, 35.14235172, 31.6716496, 29.84148401, 31.32268062,
30.58250275, 35.26514263, 33.55230269, 34.97001136, 31.09735713,
29.90509108, 33.78335499, 33.08419061, 33.9702478, 32.68267307,
32.88848951, 30.16693345, 32.85994732, 30.83277565, 34.62568305,
34.13923292, 33.50498645, 31.31095608, 34.31001321, 33.99902318,
33.7909643, 34.33340843, 32.30046602, 34.74999297, 29.87097318,
32.91255436, 30.37869556, 35.22453148, 33.91415576, 30.87027627,
34.32036758, 34.14405484, 32.52770687, 30.63412371, 30.69590367,
34.10350198, 33.51383263, 31.19792969, 35.26664132, 33.79975778,
30.9254123, 33.58382797, 32.47180323, 35.07275967, 30.97518331,
34.09754282, 31.30283331, 35.03617718, 35.0447385, 34.48088429,
34.93546837, 30.97837093, 31.14469741, 30.92743268, 34.10879646,
30.4886625, 35.00307314, 31.41065689, 31.82113768, 30.38511722,
30.39628127, 31.89778508, 31.5036342, 30.78847263, 30.63294595,
34.40494811, 32.57036077, 31.96399169, 33.90064885, 31.64029012,
34.1366935, 35.24047602, 30.50038163, 35.26178882, 30.67850437,
31.28041078, 31.13586861, 34.03564851, 30.45301463, 31.46075363,
32.79463877, 34.37256141, 31.14590299, 32.98806056, 34.61871373,
34.50000295, 33.64822723, 31.79305995, 32.95337037, 31.97535842,
33.01756184, 30.27499142, 31.52636985, 33.88390737, 29.86033691,
33.10717421, 31.13912362, 34.03308637, 29.82060846, 30.29160216,
30.68720702, 32.21043532, 32.38637581, 29.87286573, 31.91229798,
33.07799897, 30.41662694, 32.24261367, 35.3258724, 29.81198078,
29.87369792, 29.5469277, 31.07479327, 29.93749303, 31.32897414,
32.11042476, 31.74139691, 29.35309499, 31.91510643, 28.43111183,
30.64316778, 28.82045246, 31.2966231, 32.88217249, 28.85142648,
32.61772627, 28.89998879, 29.09439029, 31.17275104, 30.14374991,
32.54361297, 30.50674627, 32.01595442, 30.50549694, 30.92120556,
28.56600115, 32.6272292, 32.01189691, 32.48467475, 32.63696512,
30.92335971, 31.05045202, 30.7754939, 31.40027579, 29.12356583,
31.77973836, 28.78119827, 31.44082345, 30.73383322, 32.04126499,
30.09865077, 32.23577216, 29.08265343, 30.49423226, 31.46262176,
29.84828538, 30.18785884, 29.51834908, 29.37202672, 31.50806652,
32.40830835, 30.48030326, 31.25898945, 28.36670284, 31.28059981,
29.34232677, 30.09806882, 32.11127774, 29.59171523, 30.61713837,
29.76958526, 31.85824615, 32.16215903, 29.84655136, 31.07721122,
28.65494456, 30.9843114, 32.54863022, 31.46634971, 31.89779842,
32.82481805, 32.14782935, 32.08964421, 31.60785849, 32.91857557,
31.71183437, 31.81246841, 32.98599723, 28.95747656, 28.84662181,
31.71611474, 31.62086303, 32.53920721, 30.42499004, 28.99300588,
29.61203445, 32.4920689, 29.36255767, 32.6194317, 31.04202451,
28.75123245, 30.13704325, 30.92045914, 32.57753631, 30.83279548,
28.8546849, 30.74245368, 29.03716971, 28.37275181, 30.86814322,
30.61960665, 30.42719574, 30.27684903, 32.91275304, 29.80632759,
29.50108563, 32.6131215, 30.03530353, 30.24898855, 29.97890411,
29.91508311, 30.66431902, 29.44062756, 30.78040092, 30.42641885,
32.52252736, 32.02849124, 28.44168133, 28.77193919, 32.3661733,
32.50081923, 30.78754405, 29.31429942, 29.25319403, 29.41670938,
34.79250707, 28.45292865, 33.30658009, 36.95793072, 31.1241599,
29.47446652, 37.93368226, 29.99169743, 34.53286071, 33.30080173,
32.07298455, 34.59538339, 33.19895485, 32.39419483, 31.37985584,
33.10293436, 29.39098815, 29.6792889, 35.03296983, 37.90584009,
30.95003357, 33.20300797, 37.19244019, 35.17202829, 33.36301054,
35.45811104, 32.30603702, 35.90719466, 32.53788221, 32.98462237,
34.40384647, 34.60599035, 36.12782575, 34.22463048, 29.98624712,
35.806683, 36.85504472, 35.98104837, 35.97362738, 35.43026929,
29.52289309, 29.0544412, 28.38438112, 29.31043103, 34.55714132,
31.35110246, 35.45463173, 32.52063466, 29.64833452, 31.74827447,
31.19599864, 35.86874035, 31.36035725, 30.90048731, 36.67327499,
30.0504123, 37.41148645, 33.68205359, 29.2592527, 28.82514246,
30.62364715, 37.55578321, 32.25899523, 34.31735337, 37.1286007,
30.09667053, 37.77301539, 37.28325032, 33.82381014, 33.64911154,
32.23733708, 35.36476734, 31.19880018, 29.1404291, 30.72636631,
34.77003685, 37.31098961, 31.55246022, 28.51524079, 35.97250119,
35.08409392, 36.5458489, 37.35540297, 30.23406879, 29.17387163,
33.74088357, 29.40765925, 29.98726349, 29.58959745, 31.96605073,
31.94788415, 33.60347166, 28.43148601, 29.65454367, 36.06816061,
29.96597865, 31.90935292, 28.59771444, 32.44428733, 31.50734498,
30.23029062, 32.7213003, 33.17963215, 30.84546259, 35.61594726,
31.1375163, 33.58903731, 36.3755896, 30.15521544, 32.64832733,
29.75419547, 32.87727257, 32.86349263, 30.87051665, 34.99052692,
29.32459293, 29.75063939, 29.31336196, 30.26155711, 37.78471798,
29.29637466, 33.63983534, 29.0707227, 37.23740461, 30.46483145,
32.5191104, 32.38759822, 35.67256593, 31.96392716, 33.3250217,
35.46341363, 28.75439972, 33.2611733, 30.02014914, 35.78496489,
32.96781502, 31.43534921, 35.07596123, 34.52762462, 30.26655854,
35.32014083, 37.55183466, 34.14971103, 36.29105196, 32.40044715,
36.0587327, 31.83769864, 33.92873059, 34.70263617, 30.80816039,
30.68630199, 31.01802064, 30.80777532, 35.05333618, 27.06058834,
27.79241831, 27.33752079, 27.77903509, 26.947812, 27.8862964,
27.39365377, 27.9236377, 26.78983708, 27.98767273, 27.93024624,
27.84690108, 27.32830243, 26.81574528, 27.11055277, 27.39296015,
28.00610613, 27.71688355, 27.62271524, 27.69926561, 26.77071774,
26.75407601, 27.54772857, 26.85613667, 27.43762662, 27.45478206,
27.70204762, 27.66985159, 27.46593956, 28.00153523, 27.85391116,
26.78324156, 27.51476443, 27.54375831, 27.45536832, 27.25299275,
27.42563343, 27.35861323, 27.89703515, 27.94359525, 27.02701474,
28.01213784, 27.05632904, 27.219231, 28.00160216, 27.06621867,
26.83356071, 26.85138171, 26.9857268, 26.84488214, 27.04212578,
27.90226659, 26.88270484, 27.36445874, 27.98903653, 26.74879158,
27.91409337, 27.04442553, 27.76393403, 26.97261286, 26.82558533,
27.40286709, 26.90959192, 27.61358064, 27.67649126, 27.98923329,
27.27538051, 27.93429854, 27.24070111, 27.79609001, 27.51659686,
27.60029289, 26.85518925, 27.31821322, 27.1642527, 27.27570585,
27.67152235, 26.96014272, 27.89962397, 27.84824436)), .Names = c("days",
"hours", "TT"), class = "data.frame", row.names = c(NA, -480L
))

It seems like you have 4*4=16 plots, with 16 titles in 4 vectors.
Try this argument in your function,
main=get(paste0("D",i))[which(hours==j)]
get()function can get the object with the given object name.
I use some simulated data, just to check the titles. Looks good,
Sample codes:
x<-rnorm(50)#my simulated data
for (i in days)
{
for (j in hours)
{
hist(x,xlab="Travel Time",
ylab="Number of paths",col="blue",
main=get(paste0("D",i))[which(hours==j)], mgp=c(2.5,1,0))
}
}

This is revised to match the data that was provided.
The main idea here is to make a matrix of the titles and simply access the matrix each time you print. The code in the question looped through hours and days. Because I want to know the index, I have change this to looping through the indices, 1:4. That means that where the original code used the loop variable (hours or days) I use the index to select elements from hours or days.
I am assuming that we already have the data.frame and the OP's lists D1, D2, D3 and D4.
LabelMat = matrix(c(D1, D2, D3, D4), nrow=4)
for (i in 1:4) {
for (j in 1:4) {
# set positioning of the histogram
par("plt" = c(0.2,0.95,0.35,0.84))
# plot the histogram
hist(path$TT[path$days==days[i] & path$hours==hours[j]], breaks = seq(0,60,by=3),
xlab="Travel Time", ylab="Number of paths",
col="blue", main = LabelMat[i,j], mgp=c(2.5,1,0))
}
}

Related

Undirected network graph calculated by tidygraph shows more degree centrality than should be possible

I have a cleaned data set with 26 nodes. I am placing these 26 nodes in an undirected network graph using tidygraph, where I use the centrality_degree() function to calculate the centrality degree. However, when I graph the resulting network, my highest possible centrality degree is 40, which should not be possible. When I change the graph to directed, this is corrected.
I somewhat confused, as other methods I have used in the past, where I manually calculated the centrality degree, I have never once come across this issue.
Is this regular behaviour, or am I doing something wrong?
Reproducible example:
library(tidygraph)
library(ggraph)
library(tidyverse)
nodes <- structure(list(id = 1:26, label = c("a", "b", "c", "d", "e",
"f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x", "y", "z")), row.names = c(NA, -26L
), class = "data.frame")
edges <- structure(list(from = c(21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 17L, 17L, 17L, 17L, 17L),
to = c(1L, 12L, 3L, 16L, 24L, 4L, 10L, 6L, 22L, 2L, 8L, 1L,
12L, 13L, 3L, 18L, 16L, 24L, 5L, 7L, 14L, 4L, 10L, 6L, 9L,
22L, 15L, 2L, 20L, 8L, 21L, 12L, 13L, 3L, 16L, 24L, 5L, 7L,
14L, 4L, 10L, 6L, 22L, 15L, 2L, 8L, 17L, 21L, 1L, 13L, 3L,
16L, 5L, 7L, 14L, 10L, 6L, 9L, 22L, 15L, 2L, 20L, 8L, 17L,
21L, 1L, 3L, 18L, 16L, 5L, 7L, 14L, 4L, 10L, 6L, 25L, 9L,
22L, 15L, 20L, 8L, 17L, 21L, 11L, 1L, 12L, 13L, 18L, 16L,
24L, 5L, 7L, 14L, 4L, 10L, 6L, 25L, 9L, 22L, 15L, 20L, 8L,
17L, 1L, 3L, 10L, 6L, 22L, 20L, 8L, 21L, 11L, 1L, 13L, 3L,
18L, 24L, 7L, 4L, 10L, 6L, 25L, 9L, 22L, 15L, 2L, 20L, 8L,
17L, 21L, 11L, 1L, 12L, 13L, 18L, 16L, 5L, 7L, 14L, 10L,
6L, 25L, 9L, 22L, 15L, 20L, 8L, 17L, 1L, 3L, 18L, 16L, 7L,
14L, 4L, 10L, 6L, 9L, 22L, 15L, 2L, 20L, 8L, 17L, 21L, 11L,
1L, 12L, 13L, 3L, 18L, 16L, 24L, 14L, 4L, 10L, 6L, 25L, 9L,
22L, 15L, 2L, 20L, 8L, 11L, 1L, 3L, 18L, 16L, 7L, 10L, 6L,
9L, 22L, 15L, 2L, 20L, 8L, 17L, 21L, 11L, 1L, 12L, 13L, 3L,
18L, 16L, 24L, 5L, 7L, 14L, 10L, 6L, 25L, 9L, 22L, 15L, 2L,
20L, 8L, 17L, 21L, 11L, 1L, 12L, 13L, 3L, 18L, 16L, 24L,
5L, 7L, 14L, 4L, 6L, 25L, 9L, 22L, 15L, 2L, 20L, 8L, 17L,
21L, 11L, 1L, 12L, 13L, 3L, 18L, 24L, 5L, 7L, 14L, 4L, 10L,
25L, 9L, 22L, 15L, 2L, 20L, 8L, 21L, 1L, 13L, 3L, 18L, 5L,
10L, 6L, 22L, 2L, 20L, 8L, 21L, 1L, 13L, 3L, 18L, 16L, 24L,
4L, 10L, 6L, 22L, 15L, 2L, 20L, 8L, 11L, 1L, 12L, 13L, 3L,
16L, 24L, 5L, 7L, 14L, 4L, 10L, 6L, 25L, 9L, 15L, 2L, 20L,
8L, 17L, 21L, 1L, 12L, 3L, 18L, 16L, 24L, 7L, 10L, 6L, 25L,
9L, 22L, 2L, 20L, 8L, 17L, 21L, 11L, 1L, 12L, 13L, 3L, 18L,
16L, 24L, 5L, 7L, 14L, 4L, 6L, 25L, 9L, 22L, 15L, 20L, 8L,
17L, 21L, 11L, 1L, 3L, 16L, 24L, 7L, 10L, 6L, 22L, 2L, 8L,
21L, 11L, 1L, 12L, 13L, 3L, 18L, 16L, 24L, 14L, 4L, 10L,
6L, 25L, 9L, 22L, 2L, 20L, 7L, 6L, 25L, 22L, 8L), weight = c(3L,
1L, 3L, 2L, 1L, 1L, 5L, 1L, 8L, 2L, 1L, 2L, 3L, 2L, 5L, 1L,
4L, 1L, 4L, 4L, 4L, 1L, 5L, 13L, 3L, 7L, 3L, 2L, 3L, 8L,
1L, 1L, 1L, 15L, 10L, 7L, 2L, 4L, 2L, 5L, 19L, 23L, 6L, 2L,
11L, 7L, 1L, 1L, 2L, 3L, 3L, 5L, 4L, 5L, 4L, 4L, 21L, 2L,
9L, 8L, 1L, 1L, 12L, 1L, 2L, 1L, 3L, 1L, 6L, 6L, 5L, 6L,
1L, 6L, 22L, 2L, 2L, 9L, 8L, 3L, 13L, 1L, 5L, 6L, 4L, 10L,
13L, 3L, 41L, 46L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, 31L, 3L, 6L, 1L, 4L, 7L, 1L, 3L, 1L, 6L, 5L,
13L, 1L, 2L, 9L, 1L, 15L, 2L, 1L, 16L, 4L, 4L, 3L, 1L, 6L,
17L, 10L, 1L, 13L, 63L, 11L, 12L, 1L, 5L, 1L, 2L, 3L)), row.names = c(NA,
-383L), class = c("tbl_df", "tbl", "data.frame"))
routes_tidy <- tbl_graph(nodes=nodes, edges=edges, directed=FALSE) %>% mutate(neighbors = centrality_degree())
# Filtering out 3 nodes out of the graph as they have no connections and zoom the figure way out
ggraph(routes_tidy, layout="graphopt") +
geom_node_point(aes(size=neighbors, filter=(label!="z" & label!="s" & label!="w"))) +
geom_edge_link(aes(width=weight, alpha=weight)) +
scale_edge_width(range=c(0.2, 2)) +
geom_node_text(aes(label=label, fontface="bold", size=neighbors, filter=(label!="z" & label!="s" & label!="w")), repel=TRUE) +
labs(edge_width="N") +
theme_graph()
I'm new to the whole tidygraph thing, stumbled over this question, got confused, and figured it'd be a nice way to get to know stuff. So, I don't know if it's a bug or a feature, but the behaviour is triggered because you have doubled edges:
# Given your edges
edges %>%
filter((from == 1 & to == 2) | from == 2 & to == 1)
# A tibble: 2 x 3
from to weight
<int> <int> <int>
1 1 2 11
2 2 1 3
And those count as 2 connections in the calculation of the degree centrality. One way to remove those double edges is to convert the network to a simple network:
routes_simple <-
routes_tidy %>%
morph(to_simple) %>%
crystallise() %>%
pull(graph) %>%
getElement(1) %>%
activate(nodes) %>%
mutate(neighbors = centrality_degree())
Now the maximum degree is 22 (and the heighest possible, presumably, 25).

Calculating cumulative return for each quarter by investor

I m looking to calculate cumulative returns based on column values for each quarter grouped by investors. I tried using Return.cumulative but didn't get any success.
I appreciate if someone can help me with some easy way to calculate cumulative return in R?
structure(list(Quarter = structure(c(1L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
14L, 15L, 16L, 17L, 18L, 19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 1L,
2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L,
16L, 17L, 18L, 19L, 20L), .Label = c("2012Q1", "2012Q2", "2012Q3",
"2012Q4", "2013Q1", "2013Q2", "2013Q3", "2013Q4", "2014Q1", "2014Q2",
"2014Q3", "2014Q4", "2015Q1", "2015Q2", "2015Q3", "2015Q4", "2016Q1",
"2016Q2", "2016Q3", "2016Q4"), class = "factor"), Total_Return = c(0.040561972,
0.012692509, 0.053079761, 0.048656856, 0.037110412, 0.041422455,
0.052373109, 0.049826591, 0.053255331, 0.050956964, 0.038683073,
0.018446161, 0.039546641, 0.057108385, 0.020790648, 0.020743042,
0.015486459, 0.001202289, 0.066082963, 0.036178889, 0.037096464,
0.003068485, 0.026307213, 0.052918456, 0.019292362, 0.058390755,
0.040255949, 0.020420614, 0.024955646, 0.051180526, 0.04598829,
0.012425778, 0.036190369, 0.079480322, 0.00574259, 0.026401296,
0.018309495, 0.004887553, 0.05935355, 0.051702238, 0.080892981,
0.07076032, 0.088251171, 0.045903253, 0.029692483, 0.058297815,
0.065338687, 0.071947108, 0.074878083, 0.03989637, -0.031255434,
0.029883299, 0.008148657, 0.078836907, 0.030064965, 0.048887451,
0.034827005, -0.065304898, 0.136766281, 0.019039148, 0.075818622,
0.037509338, 0.060238115, 0.03877549, 0.027433037, 0.033627931,
0.053488836, 0.024999278, 0.016037836, 0.011863841, -0.02610323,
0.046568702, 0.021033516, 0.052322078, 0.038724408, 0.023703685,
0.013482776, 0.018159864, 0.01098064, 0.014761168, 0.010590211,
0.001237805, 0.097323777, 0.088712748, 0.034759189, 0.022507656,
0.036512294, 0.048105471, 0.030822456, 0.07172102, 0.029038233,
0.032163273, 0.015176988, 0.041039802, -0.006245358, 0.049354849,
0.00318641, 0.012988646, 0.053365281, 0.03352103, 0.030454118,
-0.011862117, 0.015271336, 0.036371973, 0.045939313, 0.047864175,
0.053764664, 0.055199293, 0.072631781, 0.063949369, 0.09113885,
0.012533175, 0.049910727, 0.055676551, 0.008841404, 0.01962578,
0.015040302, 0.020496695, 0.054345313, 0.052533934), Investor = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Active", "Total", "America",
"Africa", "China", "Europe"), class = "factor"), Date = structure(c(6L,
11L, 16L, 1L, 7L, 12L, 17L, 2L, 8L, 13L, 18L, 3L, 9L, 14L, 19L,
4L, 10L, 15L, 20L, 5L, 6L, 11L, 16L, 1L, 7L, 12L, 17L, 2L, 8L,
13L, 18L, 3L, 9L, 14L, 19L, 4L, 10L, 15L, 20L, 5L, 6L, 11L, 16L,
1L, 7L, 12L, 17L, 2L, 8L, 13L, 18L, 3L, 9L, 14L, 19L, 4L, 10L,
15L, 20L, 5L, 6L, 11L, 16L, 1L, 7L, 12L, 17L, 2L, 8L, 13L, 18L,
3L, 9L, 14L, 19L, 4L, 10L, 15L, 20L, 5L, 6L, 11L, 16L, 1L, 7L,
12L, 17L, 2L, 8L, 13L, 18L, 3L, 9L, 14L, 19L, 4L, 10L, 15L, 20L,
5L, 6L, 11L, 16L, 1L, 7L, 12L, 17L, 2L, 8L, 13L, 18L, 3L, 9L,
14L, 19L, 4L, 10L, 15L, 20L, 5L), .Label = c("12/1/2012", "12/1/2013",
"12/1/2014", "12/1/2015", "12/1/2016", "3/1/2012", "3/1/2013",
"3/1/2014", "3/1/2015", "3/1/2016", "6/1/2012", "6/1/2013", "6/1/2014",
"6/1/2015", "6/1/2016", "9/1/2012", "9/1/2013", "9/1/2014", "9/1/2015",
"9/1/2016"), class = "factor")), class = "data.frame", row.names = c(NA,
-120L))
library(tidyverse)
df %>%
arrange(Investor, Date) %>%
group_by(Investor) %>%
mutate(return_coef = 1 + Total_Return,
return_coef_cuml = cumprod(return_coef),
return_cuml = return_coef_cuml - 1) %>%
ungroup()
# A tibble: 120 x 7
# Groups: Investor [6]
Quarter Total_Return Investor Date return_coef return_coef_cuml return_cuml
<fct> <dbl> <fct> <fct> <dbl> <dbl> <dbl>
1 2012Q4 0.0487 Active 12/1/2012 1.05 1.05 0.0487
2 2013Q4 0.0498 Active 12/1/2013 1.05 1.10 0.101
3 2014Q4 0.0184 Active 12/1/2014 1.02 1.12 0.121
4 2015Q4 0.0207 Active 12/1/2015 1.02 1.14 0.144
5 2016Q4 0.0362 Active 12/1/2016 1.04 1.19 0.186
6 2012Q1 0.0406 Active 3/1/2012 1.04 1.23 0.234
7 2013Q1 0.0371 Active 3/1/2013 1.04 1.28 0.280
8 2014Q1 0.0533 Active 3/1/2014 1.05 1.35 0.348
9 2015Q1 0.0395 Active 3/1/2015 1.04 1.40 0.401
10 2016Q1 0.0155 Active 3/1/2016 1.02 1.42 0.423

Removing greater than and less than characters and number of decimals in data frame in r

I am having a dataframe of 2 variables
structure(list(X1 = structure(c(17L, 27L, 6L, 1L, 28L, 1L, 1L,4L, 17L, 28L, 28L, 12L, 21L, 28L, 28L, 8L, 28L, 1L, 1L, 10L, 4L, 21L, 30L, 1L, 8L, 28L, 1L, 1L, 1L, 1L, 8L, 1L, 17L, 1L, 1L, 28L, 8L, 23L, 15L, 23L, 25L, 13L, 8L, 4L, 28L, 10L, 1L, 30L, 13L, 4L, 1L, 1L, 17L, 13L, 13L, 8L, 4L, 4L, 4L, 28L, 28L, 13L,1L, 4L, 28L, 1L, 1L, 1L, 1L, 1L, 12L, 2L, 6L, 1L, 8L, 1L, 21L, 1L, 21L, 1L, 30L,13L, 25L, 17L, 1L, 28L, 13L, 1L, 1L, 1L, 1L,8L, 30L, 25L, 28L, 4L, 1L, 13L, 17L, 4L,1L, 1L, 28L, 1L, 1L, 8L, 1L, 8L, 1L, 13L, 1L, 1L, 1L, 4L, 6L, 1L, 1L, 30L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 6L, 1L, 15L, 21L, 10L, 21L, 1L, 10L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 28L, 28L, 1L, 30L, 15L, 25L, 6L, 17L, 25L, 15L, 8L, 18L, 22L, 14L, 22L, 28L, 30L, 3L, 30L, 14L, 18L, 22L, 24L, 10L, 26L, 26L, 18L, 26L, 30L, 29L, 18L, 14L, 9L, 9L, 16L, 16L, 29L, 18L, 16L, 27L, 24L, 14L, 26L, 5L, 22L, 28L, 22L, 11L, 9L, 26L, 30L, 18L, 28L, 16L, 26L, 7L, 30L, 7L, 28L, 5L, 18L, 9L, 26L, 24L, 27L, 16L, 16L, 14L, 26L, 29L, 5L, 22L, 24L, 26L, 18L, 27L, 9L, 18L, 11L, 14L, 18L, 22L, 29L, 26L, 22L, 26L, 20L, 24L, 14L, 7L, 16L, 24L, 26L, 29L, 24L, 24L, 24L, 20L, 20L, 24L, 11L, 20L, 29L, 16L, 18L, 24L, 24L, 7L, 24L, 18L, 11L, 11L, 24L, 24L, 7L, 11L, 18L, 24L, 24L, 16L, 29L, 7L, 30L, 24L, 22L, 24L, 18L, 26L, 9L, 9L, 24L, 29L, 9L, 24L, 30L, 11L, 24L, 16L, 26L, 26L, 26L, 30L, 26L, 16L, 26L, 24L, 29L, 20L, 24L, 14L, 9L, 7L, 29L, 29L, 15L, 6L, 15L, 2L, 6L, 6L, 3L, 2L, 17L, 30L, 27L, 23L, 2L, 15L, 8L, 13L, 21L, 28L, 23L, 25L, 1L, 25L, 19L, 27L, 23L, 15L, 19L, 19L, 23L, 2L, 27L, 27L, 15L, 2L, 2L, 3L, 23L, 2L, 23L, 6L, 2L, 15L, 13L,1L, 1L, 13L, 28L, 1L, 1L, 28L, 21L, 1L, 28L, 4L, 1L, 17L, 17L, 13L, 21L, 1L, 1L, 1L, 17L, 1L, 1L, 17L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 13L, 1L, 1L, 1L, 1L, 8L,25L, 1L, 28L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 8L, 4L, 1L, 25L, 28L, 13L, 1L, 1L, 28L, 1L, 4L, 1L, 1L, 8L, 1L, 8L, 13L, 4L, 28L, 21L, 28L, 28L, 28L, 28L, 28L, 8L, 1L, 1L, 1L, 1L, 13L, 21L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 28L, 4L, 1L, 17L, 17L, 28L, 1L, 13L, 8L, 17L, 1L, 13L, 13L, 8L, 4L, 1L, 17L, 25L, 1L, 1L, 8L, 8L, 1L, 4L, 17L, 21L),
.Label = c("<8", ">1024", "1024", "11", "11.000000000000007", "128", "128.00000000000009", "16", "16.000000000000007", "181", "181.00000000000006", "22", "23", "23.000000000000011", "256", "256.00000000000017", "32", "32.000000000000014", "362", "362.00000000000017", "45", "45.000000000000014", "512", "512.00000000000045", "64", "64.000000000000028", "724", "8", "8.0000000000000018", "90"),
class = "factor"),
X2 = structure(c(7L, 2L, 2L, 8L, 18L, 4L, 13L, 18L, 8L, 13L, 8L, 18L, 12L, 13L, 18L, 16L, 7L, 5L, 1L, 16L, 18L, 18L, 18L, 12L, 7L, 1L, 4L, 4L, 2L,16L, 12L, 12L, 2L, 2L, 13L, 13L, 18L, 2L, 16L, 2L, 16L, 16L, 2L, 12L, 16L, 2L, 12L,2L, 2L, 16L, 16L, 2L, 2L, 2L, 2L, 2L, 7L, 18L, 18L, 18L, 13L, 18L, 13L, 18L, 9L, 13L, 8L, 4L, 1L, 13L, 8L, 2L, 16L, 12L, 7L, 7L, 18L, 18L, 18L, 12L, 16L, 7L, 16L, 7L, 12L, 12L, 16L, 12L, 13L, 13L, 12L, 16L, 12L, 12L, 7L, 7L, 13L,16L, 7L, 18L, 16L, 13L, 18L, 4L, 12L, 7L, 4L, 18L, 18L, 18L, 9L, 17L, 13L, 7L, 12L, 7L, 18L, 12L, 18L, 13L, 9L, 1L, 18L, 1L, 13L, 13L, 13L, 1L, 1L, 13L, 12L, 4L, 1L,1L, 4L, 12L, 9L, 1L, 1L, 1L, 2L, 12L, 9L, 2L, 18L, 2L, 18L, 7L, 12L, 1L, 9L, 9L, 7L, 18L, 9L, 18L, 1L, 12L, 13L, 12L, 16L, 7L, 12L, 7L, 16L, 2L, 12L,7L, 16L, 12L, 16L, 2L, 12L, 2L, 15L, 7L, 7L, 2L, 7L, 3L, 12L, 16L, 1L, 17L, 2L, 18L, 5L, 7L, 1L, 16L, 7L, 10L, 1L, 12L, 18L, 16L, 16L, 13L, 12L, 7L, 2L, 1L, 9L, 18L, 12L, 13L, 2L, 2L, 12L, 2L, 2L, 2L, 16L, 2L, 1L, 18L, 12L, 7L, 2L, 2L, 12L, 7L, 12L, 4L, 2L, 18L, 13L, 2L, 16L, 7L, 2L, 2L, 12L, 2L, 14L, 12L, 12L, 16L, 1L, 2L, 4L, 2L, 2L, 2L, 17L, 2L, 2L, 2L, 18L, 16L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 12L, 2L, 2L, 1L, 2L, 12L, 18L, 2L, 15L, 16L, 16L, 2L, 2L, 2L, 2L, 11L, 12L, 14L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 16L, 16L, 12L, 2L, 12L, 2L, 2L, 2L, 12L, 2L,16L, 2L, 12L, 14L, 7L, 2L, 4L, 14L, 2L, 16L, 15L, 7L, 16L, 18L, 2L, 16L, 2L, 2L, 12L, 12L, 2L, 2L, 4L, 2L, 2L, 2L, 16L, 2L, 12L,18L, 3L, 16L, 2L, 2L, 13L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 16L, 16L, 2L, 2L, 4L, 4L, 11L, 13L, 4L, 4L, 8L, 4L, 13L, 1L, 4L, 1L, 1L, 2L, 2L, 11L, 18L, 8L, 8L, 4L, 7L, 8L, 4L, 8L, 4L, 4L, 8L, 8L, 1L, 4L, 8L, 4L, 13L, 1L, 6L, 1L, 17L, 2L, 2L, 8L, 18L, 8L, 8L, 4L, 7L, 8L, 17L, 8L, 4L, 1L, 4L, 13L, 1L, 2L, 4L, 16L, 13L, 4L, 4L, 17L, 4L, 7L, 4L, 4L, 1L, 1L, 4L, 1L, 17L, 8L, 1L, 8L, 1L, 4L, 1L, 8L, 8L, 8L, 1L, 13L, 16L, 16L, 17L, 8L, 13L, 1L, 4L, 7L, 1L, 1L, 4L, 4L, 8L, 6L, 4L, 1L, 12L, 13L, 8L, 4L, 4L, 18L, 2L, 4L, 8L, 13L, 17L,13L, 18L, 7L, 16L, 7L, 1L, 13L, 8L, 13L, 4L, 1L, 7L),
.Label = c("<8", ">1024", "1024", "11", "128", "16", "181", "22", "23", "256", "32", "362", "45", "512", "64", "724", "8", "90"), class = "factor")),
.Names = c("X1", "X2"),
row.names = c(NA, -471L),
class = "data.frame")
I have 2 questions
1) Each one is having some greater than values and some with less than values. i want to remove the > and < characters from data frame and retain only the number in the dataframe. I can do it in excel but i want to learn the code for learning it in R.
2) I want to reduce the number of decimals to integer/whole number as some are having more number of decimals.
It may be a small question, but i am struggling to do this. i highly appreciate for this help.
You can use dplyr::mutate_all and stringr::str_replace_all.
Decimals are directly approximated by as.numeric since it is ~10^(-13)magnitude.
your_df <- structure(list(X1 = structure(c(17L, 27L, 6L, 1L, 28L, 1L, 1L,4L, 17L, 28L, 28L, 12L, 21L, 28L, 28L, 8L, 28L, 1L, 1L, 10L, 4L, 21L, 30L, 1L, 8L, 28L, 1L, 1L, 1L, 1L, 8L, 1L, 17L, 1L, 1L, 28L, 8L, 23L, 15L, 23L, 25L, 13L, 8L, 4L, 28L, 10L, 1L, 30L, 13L, 4L, 1L, 1L, 17L, 13L, 13L, 8L, 4L, 4L, 4L, 28L, 28L, 13L,1L, 4L, 28L, 1L, 1L, 1L, 1L, 1L, 12L, 2L, 6L, 1L, 8L, 1L, 21L, 1L, 21L, 1L, 30L,13L, 25L, 17L, 1L, 28L, 13L, 1L, 1L, 1L, 1L,8L, 30L, 25L, 28L, 4L, 1L, 13L, 17L, 4L,1L, 1L, 28L, 1L, 1L, 8L, 1L, 8L, 1L, 13L, 1L, 1L, 1L, 4L, 6L, 1L, 1L, 30L,1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 6L, 6L, 1L, 15L, 21L, 10L, 21L, 1L, 10L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 28L, 28L, 1L, 30L, 15L, 25L, 6L, 17L, 25L, 15L, 8L, 18L, 22L, 14L, 22L, 28L, 30L, 3L, 30L, 14L, 18L, 22L, 24L, 10L, 26L, 26L, 18L, 26L, 30L, 29L, 18L, 14L, 9L, 9L, 16L, 16L, 29L, 18L, 16L, 27L, 24L, 14L, 26L, 5L, 22L, 28L, 22L, 11L, 9L, 26L, 30L, 18L, 28L, 16L, 26L, 7L, 30L, 7L, 28L, 5L, 18L, 9L, 26L, 24L, 27L, 16L, 16L, 14L, 26L, 29L, 5L, 22L, 24L, 26L, 18L, 27L, 9L, 18L, 11L, 14L, 18L, 22L, 29L, 26L, 22L, 26L, 20L, 24L, 14L, 7L, 16L, 24L, 26L, 29L, 24L, 24L, 24L, 20L, 20L, 24L, 11L, 20L, 29L, 16L, 18L, 24L, 24L, 7L, 24L, 18L, 11L, 11L, 24L, 24L, 7L, 11L, 18L, 24L, 24L, 16L, 29L, 7L, 30L, 24L, 22L, 24L, 18L, 26L, 9L, 9L, 24L, 29L, 9L, 24L, 30L, 11L, 24L, 16L, 26L, 26L, 26L, 30L, 26L, 16L, 26L, 24L, 29L, 20L, 24L, 14L, 9L, 7L, 29L, 29L, 15L, 6L, 15L, 2L, 6L, 6L, 3L, 2L, 17L, 30L, 27L, 23L, 2L, 15L, 8L, 13L, 21L, 28L, 23L, 25L, 1L, 25L, 19L, 27L, 23L, 15L, 19L, 19L, 23L, 2L, 27L, 27L, 15L, 2L, 2L, 3L, 23L, 2L, 23L, 6L, 2L, 15L, 13L,1L, 1L, 13L, 28L, 1L, 1L, 28L, 21L, 1L, 28L, 4L, 1L, 17L, 17L, 13L, 21L, 1L, 1L, 1L, 17L, 1L, 1L, 17L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 13L, 1L, 1L, 1L, 1L, 8L,25L, 1L, 28L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 8L, 4L, 1L, 25L, 28L, 13L, 1L, 1L, 28L, 1L, 4L, 1L, 1L, 8L, 1L, 8L, 13L, 4L, 28L, 21L, 28L, 28L, 28L, 28L, 28L, 8L, 1L, 1L, 1L, 1L, 13L, 21L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 28L, 4L, 1L, 17L, 17L, 28L, 1L, 13L, 8L, 17L, 1L, 13L, 13L, 8L, 4L, 1L, 17L, 25L, 1L, 1L, 8L, 8L, 1L, 4L, 17L, 21L), .Label = c("<8", ">1024", "1024", "11", "11.000000000000007", "128", "128.00000000000009", "16", "16.000000000000007", "181", "181.00000000000006", "22", "23", "23.000000000000011", "256", "256.00000000000017", "32", "32.000000000000014", "362", "362.00000000000017", "45", "45.000000000000014", "512", "512.00000000000045", "64", "64.000000000000028", "724", "8", "8.0000000000000018", "90"), class = "factor"), X2 = structure(c(7L, 2L, 2L, 8L, 18L, 4L, 13L, 18L, 8L, 13L, 8L, 18L, 12L, 13L, 18L, 16L, 7L, 5L, 1L, 16L, 18L, 18L, 18L, 12L, 7L, 1L, 4L, 4L, 2L,16L, 12L, 12L, 2L, 2L, 13L, 13L, 18L, 2L, 16L, 2L, 16L, 16L, 2L, 12L, 16L, 2L, 12L,2L, 2L, 16L, 16L, 2L, 2L, 2L, 2L, 2L, 7L, 18L, 18L, 18L, 13L, 18L, 13L, 18L, 9L, 13L, 8L, 4L, 1L, 13L, 8L, 2L, 16L, 12L, 7L, 7L, 18L, 18L, 18L, 12L, 16L, 7L, 16L, 7L, 12L, 12L, 16L, 12L, 13L, 13L, 12L, 16L, 12L, 12L, 7L, 7L, 13L,16L, 7L, 18L, 16L, 13L, 18L, 4L, 12L, 7L, 4L, 18L, 18L, 18L, 9L, 17L, 13L, 7L, 12L, 7L, 18L, 12L, 18L, 13L, 9L, 1L, 18L, 1L, 13L, 13L, 13L, 1L, 1L, 13L, 12L, 4L, 1L,1L, 4L, 12L, 9L, 1L, 1L, 1L, 2L, 12L, 9L, 2L, 18L, 2L, 18L, 7L, 12L, 1L, 9L, 9L, 7L, 18L, 9L, 18L, 1L, 12L, 13L,
12L, 16L, 7L, 12L, 7L, 16L, 2L, 12L,7L, 16L, 12L, 16L, 2L, 12L, 2L, 15L, 7L, 7L, 2L, 7L, 3L, 12L, 16L,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L, 7L, 1L, 1L, 4L, 4L, 8L, 6L, 4L, 1L, 12L, 13L, 8L, 4L, 4L, 18L, 2L, 4L, 8L, 13L, 17L,13L, 18L, 7L, 16L, 7L, 1L, 13L, 8L, 13L, 4L, 1L, 7L),
.Label = c("<8", ">1024", "1024", "11", "128", "16", "181", "22", "23", "256", "32", "362", "45", "512", "64", "724", "8", "90"), class = "factor")), .Names = c("X1", "X2"), row.names = c(NA, -471L), class = "data.frame")
library(dplyr)
library(stringr)
mutate_all(your_df, function(x) as.numeric(str_replace_all(x, pattern = "<|>", replacement = "")))
#> X1 X2
#> 1 32 181
#> 2 724 1024
#> 3 128 1024
#> 4 8 22
#> 5 8 90
#> 6 8 11
#> 7 8 45
#> 8 11 90
#> 9 32 22
#> 10 8 45
#> 11 8 22
#> 12 22 90
#> 13 45 362
You can do this with base R:
my_df <- as.data.frame(sapply(my_df, gsub, pattern = "<|>", replacement = ""))
my_df <- as.data.frame(sapply(my_df, as.numeric))
my_df
# X1 X2
# 1 8 23
# 2 8 90
# 3 8 8
# 4 8 362
# 5 8 45
# 6 90 362
# 7 256 724
# 8 64 181
# 9 128 362
# 10 32 181
# 11 64 724
# 12 256 1024
# 13 16 362
# 14 32.000000000000014 181
# 15 45.000000000000014 724
# 16 23.000000000000011 362
# 17 45.000000000000014 724
# 18 8 1024
# 19 90 362
# 20 1024 1024
# 21 90 64
# 22 23.000000000000011 181
# 23 32.000000000000014 181
# 24 45.000000000000014 1024
# 25 512.00000000000045 181
If you only want to round the decimals, but keep the < and > signs you can do the following (without perfoming the steps above):
sapply(my_df,
function(x) paste0(gsub(x, pattern = "\\d|\\.", replacement = ""),
round(as.numeric(gsub(x, pattern = "<|>", replacement = "")))))
# X1 X2
# [1,] "<8" "23"
# [2,] "<8" "90"
# [3,] "8" "<8"
# [4,] "8" "362"
# [5,] "<8" "45"
# [6,] "90" "362"
# [7,] "256" "724"
# [8,] "64" "181"
# [9,] "128" "362"
# [10,] "32" "181"
# [11,] "64" "724"
# [12,] "256" ">1024"
# [13,] "16" "362"
# [14,] "32" "181"
# [15,] "45" "724"
# [16,] "23" "362"
# [17,] "45" "724"
# [18,] "8" ">1024"
# [19,] "90" "362"
# [20,] "1024" ">1024"
# [21,] "90" "64"
# [22,] "23" "181"
# [23,] "32" "181"
# [24,] "45" ">1024"
# [25,] "512" "181"
How it works
sapply takes the data.frame and applys the function specified after the comma to each column of the data.frame. gsub substitute the pattern with the replacement in x (a column of the data.frame). There I used regular expression, so \\d means all digits (0-9) and \\. the dot and | combines them with a OR logic.
stringr-solution
There's a shorter solution with stringr:
library(stringr)
sapply(my_df,
function(x) str_c(str_extract(x, "[<>]?"),
round(as.numeric(str_extract(x, "\\d+")))))
Here the pattern we want to have are extracted and then combined again after rounding the decimals.
Data
my_df <-
structure(list(X1 = structure(c(1L, 1L, 28L, 28L, 1L, 30L, 15L,
25L, 6L, 17L, 25L, 15L, 8L, 18L,
22L, 14L, 22L, 28L, 30L, 3L, 30L,
14L, 18L, 22L, 24L),
.Label = c("<8", ">1024", "1024", "11",
"11.000000000000007", "128",
"128.00000000000009", "16",
"16.000000000000007", "181",
"181.00000000000006", "22",
"23", "23.000000000000011",
"256", "256.00000000000017",
"32", "32.000000000000014",
"362", "362.00000000000017",
"45", "45.000000000000014",
"512", "512.00000000000045",
"64", "64.000000000000028",
"724", "8",
"8.0000000000000018", "90"),
class = "factor"),
X2 = structure(c(9L, 18L, 1L, 12L, 13L, 12L, 16L, 7L,
12L, 7L, 16L, 2L, 12L, 7L, 16L, 12L,
16L, 2L, 12L, 2L, 15L, 7L, 7L, 2L, 7L),
.Label = c("<8", ">1024", "1024", "11",
"128", "16", "181", "22", "23",
"256", "32", "362", "45", "512",
"64", "724", "8", "90"),
class = "factor")),
.Names = c("X1", "X2"),
row.names = c(NA, -25L),
class = "data.frame")
# X1 X2
# 1 <8 23
# 2 <8 90
# 3 8 <8
# 4 8 362
# 5 <8 45
# 6 90 362
# 7 256 724
# 8 64 181
# 9 128 362
# 10 32 181
# 11 64 724
# 12 256 >1024
# 13 16 362
# 14 32.000000000000014 181
# 15 45.000000000000014 724
# 16 23.000000000000011 362
# 17 45.000000000000014 724
# 18 8 >1024
# 19 90 362
# 20 1024 >1024
# 21 90 64
# 22 23.000000000000011 181
# 23 32.000000000000014 181
# 24 45.000000000000014 >1024
# 25 512.00000000000045 181

R: Shiny - How to subset and then make a bargraph based on daterangeInput

i've this data frame:
date sessions Fuentes
1 2014-12-01 197 Directo
2 2014-12-01 1 Referencias
3 2014-12-01 7 Social Media
4 2014-12-01 13 SEO
5 2014-12-01 1 Email
6 2014-12-01 1 Referencias
This is the data after using dput():
structure(list(date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L,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 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L), .Label = c("2014-12-01",
"2014-12-02", "2014-12-03", "2014-12-04", "2014-12-05", "2014-12-06",
"2014-12-07", "2014-12-08", "2014-12-09", "2014-12-10", "2014-12-11",
"2014-12-12", "2014-12-13", "2014-12-14", "2014-12-15", "2014-12-16",
"2014-12-17", "2014-12-18", "2014-12-19", "2014-12-20", "2014-12-21",
"2014-12-22", "2014-12-23", "2014-12-24", "2014-12-25", "2014-12-26",
"2014-12-27", "2014-12-28", "2014-12-29", "2014-12-30", "2014-12-31"
), class = "factor"), sessions = c(197L, 1L, 7L, 13L, 1L, 1L,
10L, 1L, 3L, 3L, 5L, 3L, 566L, 1L, 27L, 159L, 7L, 1L, 6L, 1L,
1L, 4L, 1L, 6L, 10L, 129L, 1L, 7L, 2L, 1L, 10L, 1L, 5L, 6L, 9L,
1L, 28L, 1L, 7L, 386L, 1L, 146L, 1L, 89L, 41L, 9L, 1L, 1L, 1L,
6L, 3L, 4L, 182L, 1L, 5L, 8L, 2L, 1L, 1L, 4L, 1L, 1L, 2L, 3L,
2L, 524L, 4L, 26L, 1L, 152L, 4L, 2L, 3L, 1L, 2L, 2L, 1L, 5L,
10L, 142L, 1L, 1L, 8L, 1L, 3L, 1L, 1L, 1L, 1L, 7L, 4L, 13L, 3L,
375L, 3L, 2L, 147L, 1L, 101L, 29L, 4L, 1L, 1L, 2L, 3L, 1L, 1L,
2L, 1L, 7L, 5L, 5L, 224L, 3L, 12L, 1L, 7L, 2L, 1L, 4L, 141L,
4L, 632L, 2L, 2L, 32L, 1L, 138L, 1L, 1L, 9L, 5L, 1L, 1L, 1L,
2L, 1L, 6L, 3L, 139L, 4L, 1L, 9L, 1L, 1L, 5L, 9L, 8L, 36L, 1L,
537L, 1L, 2L, 5L, 3L, 174L, 1L, 106L, 39L, 9L, 2L, 2L, 2L, 3L,
1L, 6L, 3L, 2L, 689L, 1L, 14L, 2L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 6L, 6L, 6L, 5L, 5L, 5L, 5L, 7L,
5L, 6L, 5L, 5L, 7L, 5L, 5L, 5L, 2L, 2L, 5L, 5L, 5L, 5L, 5L, 6L,
3L, 6L, 4L, 4L, 5L, 4L, 5L, 6L, 5L, 5L, 5L, 4L, 5L, 5L, 5L, 5L,
4L, 2L, 5L, 5L, 4L, 4L, 6L, 3L, 6L, 6L, 5L, 5L, 5L, 7L, 6L, 5L,
5L, 5L, 5L, 5L, 4L, 2L, 5L, 5L, 5L, 5L, 5L, 6L, 7L, 3L, 6L, 4L,
6L, 5L, 5L, 5L, 7L, 5L, 1L, 6L, 7L, 5L, 5L, 4L, 5L, 5L, 4L, 5L,
5L, 5L, 6L, 7L, 3L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 6L, 5L, 5L, 5L,
5L, 4L, 5L, 2L, 5L, 5L, 5L, 5L, 6L, 3L, 5L, 4L, 4L, 6L, 4L, 5L,
5L, 5L, 7L, 6L, 5L, 5L, 4L, 5L, 5L, 4L, 4L, 5L, 5L, 5L, 3L, 6L,
6L, 5L, 5L, 7L, 6L, 5L, 5L, 5L, 5L, 7L, 5L, 4L, 2L, 5L, 5L, 5L,
5L, 5L, 6L, 7L, 3L, 4L, 6L, 5L, 5L, 4L, 5L, 5L, 7L, 1L, 6L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 5L, 6L, 3L, 6L, 6L, 6L, 5L, 5L,
5L, 5L, 7L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 3L, 6L, 4L, 6L, 5L,
5L, 7L, 7L, 5L, 6L, 5L, 5L, 5L, 5L), .Label = c("Adwords", "Campañas",
"Directo", "Email", "Referencias", "SEO", "Social Media"), class = "factor")), .Names = c("date",
"sessions", "Fuentes"), class = "data.frame", row.names = c(NA,
-1724L))
In a Shiny App, want to plot bars for Fuentes, acording to a data range specified by the user. I use daterangeInput in my ui.R, but cannot get it to plot what I need.
My ui.R
library(shiny)
# Define the overall UI
shinyUI(
# Use a fluid Bootstrap layout
fluidPage(
# Give the page a title
br(),
br(),
titlePanel("Visitas por fuente"),
# Generate a row with a sidebar
sidebarLayout(
# Define the sidebar with one input
sidebarPanel(
dateRangeInput("dates", label = h3("Date range"),
start = "2014-12-01", end = "2014-12-31")
),
# Create a spot for the barplot
mainPanel(
plotOutput("VisitasFuente")
)
)
)
)
My server.R ### Edited - Now can plot, but labels appeare as a blur from botton to top.
library(ggplot2)
library(dplyr)
require(scales)
Visitas_Por_Fuente <- read.csv("D:\\RCoursera\\Movistar- App-2\\Visitas_Por_Fuente_Dic.csv")
labels = c("Directo", "Email", "Referencias", "SEO", "Social Media")
Visitas_Por_Fuente$date <- as.Date(Visitas_Por_Fuente$date)
shinyServer(
function(input, output) {
output$VisitasFuente <- renderPlot({
# Filter the data based on user selection month
date_seq <- seq(input$dates[1], input$dates[2], by = "day")
#VisitasData <- filter(Visitas_Por_Fuente, date >= input$dates[1],
# date <= input$dates[2])
VisitasData <- filter(Visitas_Por_Fuente, date %in% date_seq & Fuentes %in% labels)
# Bar graph using ggplot2 library
ggplot(VisitasData, aes(factor(Fuentes), sessions, fill = Fuentes)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label = comma(sessions)), position=position_dodge(width=0.9), vjust=-0.25) +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9"),
labels = c("Directo", "Email", "References",
"SEO", "Social Media"),
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2"))
})
})
This was fixied by loading the corresponded packages
Thanks to #goodtimeslim, i've made the recomendations you gave me. But now i get:
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
What could it be? Thanks again.
#
Okay, first thing, you need to tell R that Visitas_Por_Fuente$date is a date, with Visitas_Por_Fuente$date <- as.Date(Visitas_Por_Fuente$date) .
You can do this right after you import your data at the beginning.
Now you want to create a range of dates, in your server file, using the date inputs, like so:
date_seq <- seq(input$dates[1], input$dates[2], by = "day")
Now you just need to change your filter, so that the date is in that sequence, like so:
VisitasData <- filter(Visitas_Por_Fuente, date %in% date_seq)
Now I admit that doesn't solve everything, I was getting some weird errors with your ggplot code, but this will solve the subsetting issue.
This issue with your ggplot is that your data has 7 variables, but you're only giving it information for 5. If you just want those 5 variables, then at the top (right after you import your data), write this:
labels = c("Directo", "Email", "References", "SEO", "Social Media")
and then, for your plot, get rid of the scale_manual line and replace it with:
scale_x_discrete(limit = labels)
That'll force those 5 on there, and at the moment, it'll do it in whatever color R wants. I'll let you figure out the rest if you want to change it.
Let me know if this is clear enough or if you just want the whole server.r code.
edit: Okay, I fixed it. You had an error in your code, you have "References", but in your data, it's "Referencias". So now, assuming you still want those five variables only, and not all 7, do this: change labels (at the top) like so:
labels = c("Directo", "Email", "Referencias", "SEO", "Social Media")
Change your filter like so:
VisitasData <- filter(Visitas_Por_Fuente, date %in% date_seq & Fuentes %in% labels)
Then you can get rid of that scale_x_discrete line I had, and put your line back in. It should all work now. (Except edit your labels in the manual_scale part to reflect the proper "Referencias".
edit 2: Here's the full server.r that runs just fine on my computer. I've made some slight changes for consistency/clarity, but otherwise it's mostly the same.
library(ggplot2)
Visitas_Por_Fuente <- read.csv("visitas.csv") ## put your path here
labelsF = c("Directo", "Email", "Referencias", "SEO", "Social Media")
Visitas_Por_Fuente$date <- as.Date(Visitas_Por_Fuente$date)
shinyServer(
function(input, output) {
output$VisitasFuente <- renderPlot({
# Filter the data based on user selection month
date_seq <- seq(input$dates[1], input$dates[2], by = "day")
#VisitasData <- filter(Visitas_Por_Fuente, date >= input$dates[1],
# date <= input$dates[2])
VisitasData <- filter(Visitas_Por_Fuente, date %in% date_seq & Fuentes %in% labelsF)
# Bar graph using ggplot2 library
ggplot(VisitasData, aes(factor(Fuentes), sessions, fill = Fuentes)) +
geom_bar(stat="identity", position = "dodge") +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9"),
labels = labelsF,
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2"))
})
})

R: Shiny and Ggplot2 show different plot with same code

Have data for everyday of dicember 2014. want to plot a barchart according to the selection of dates:
Original data:
structure(list(date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,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 8L, 8L, 8L, 8L,
8L, 8L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L,
13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L,
15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
17L, 17L, 17L, 17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L,
19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L,
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L,
24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L, 25L,
25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L,
31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L), .Label = c("2014-12-01",
"2014-12-02", "2014-12-03", "2014-12-04", "2014-12-05", "2014-12-06",
"2014-12-07", "2014-12-08", "2014-12-09", "2014-12-10", "2014-12-11",
"2014-12-12", "2014-12-13", "2014-12-14", "2014-12-15", "2014-12-16",
"2014-12-17", "2014-12-18", "2014-12-19", "2014-12-20", "2014-12-21",
"2014-12-22", "2014-12-23", "2014-12-24", "2014-12-25", "2014-12-26",
"2014-12-27", "2014-12-28", "2014-12-29", "2014-12-30", "2014-12-31"
), class = "factor"), sessions = c(197L, 1L, 7L, 13L, 1L, 1L,
10L, 1L, 3L, 3L, 5L, 3L, 566L, 1L, 27L, 159L, 7L, 1L, 6L, 1L,
1L, 4L, 1L, 6L, 10L, 129L, 1L, 7L, 2L, 1L, 10L, 1L, 5L, 6L, 9L,
1L, 28L, 1L, 7L, 386L, 1L, 146L, 1L, 89L, 41L, 9L, 1L, 1L, 1L,
6L, 3L, 4L, 182L, 1L, 5L, 8L, 2L, 1L, 1L, 4L, 1L, 1L, 2L, 3L,
2L, 524L, 4L, 26L, 1L, 152L, 4L, 2L, 3L, 1L, 2L, 2L, 1L, 5L,
10L, 142L, 1L, 1L, 8L, 1L, 3L, 1L, 1L, 1L, 1L, 7L, 4L, 13L, 3L,
375L, 3L, 2L, 147L, 1L, 101L, 29L, 4L, 1L, 1L, 2L, 3L, 1L, 1L,
2L, 1L, 7L, 5L, 5L, 224L, 3L, 12L, 1L, 7L, 2L, 1L, 4L, 141L,
4L, 632L, 2L, 2L, 32L, 1L, 138L, 1L, 1L, 9L, 5L, 1L, 1L, 1L,
2L, 1L, 6L, 3L, 139L, 4L, 1L, 9L, 1L, 1L, 5L, 9L, 8L, 36L, 1L,
537L, 1L, 2L, 5L, 3L, 174L, 1L, 106L, 39L, 9L, 2L, 2L, 2L, 3L,
1L, 6L, 3L, 2L, 689L, 1L, 14L, 2L, 2L, 35L, 1L, 15L, 1L, 1L,
1L, 3L, 20L, 465L, 1L, 3269L, 1L, 2L, 1L, 9L, 1L, 32L, 6L, 2L,
293L, 1L, 3L, 1L, 11L, 2L, 1L, 9L, 10L, 1L, 1L, 1L, 1L, 1L, 2L,
7L, 2L, 433L, 1L, 4L, 1L, 1L, 3L, 19L, 1L, 2L, 1L, 1L, 12L, 1L,
4L, 1L, 1L, 3L, 37L, 10L, 88L, 6L, 1808L, 5L, 4L, 451L, 5L, 219L,
112L, 4L, 3L, 1L, 6L, 1L, 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 4L,
6L, 5L, 5L, 5L, 7L, 5L, 1L, 6L, 7L, 5L, 5L, 4L, 5L, 5L, 4L, 5L,
5L, 5L, 6L, 7L, 3L, 6L, 6L, 6L, 5L, 5L, 5L, 5L, 6L, 5L, 5L, 5L,
5L, 4L, 5L, 2L, 5L, 5L, 5L, 5L, 6L, 3L, 5L, 4L, 4L, 6L, 4L, 5L,
5L, 5L, 7L, 6L, 5L, 5L, 4L, 5L, 5L, 4L, 4L, 5L, 5L, 5L, 3L, 6L,
6L, 5L, 5L, 7L, 6L, 5L, 5L, 5L, 5L, 7L, 5L, 4L, 2L, 5L, 5L, 5L,
5L, 5L, 6L, 7L, 3L, 4L, 6L, 5L, 5L, 4L, 5L, 5L, 7L, 1L, 6L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 5L, 6L, 3L, 6L, 6L, 6L, 5L, 5L,
5L, 5L, 7L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 3L, 6L, 4L, 6L, 5L,
5L, 7L, 7L, 5L, 6L, 5L, 5L, 5L, 5L), .Label = c("Adwords", "Campañas",
"Directo", "Email", "Referencias", "SEO", "Social Media"), class = "factor")), .Names = c("date",
"sessions", "Fuentes"), class = "data.frame", row.names = c(NA,
-1724L))
My data after the summarise function:
Fuentes sessions
1 Adwords 71
2 Campa�as 280
3 Directo 11610
4 Email 437
5 Referencias 13143
6 SEO 39837
7 Social Media 5981
Howcome my shiny code does not print right my plot?
1) when used within Shiny, the label appears like blured:
do a summarise before plotting (see code below):
server.R file:
library(ggplot2)
library(dplyr)
require(scales)
Visitas_Por_Fuente <- read.csv("D:\\RCoursera\\Movistar-App-2\\Visitas_Por_Fuente_Dic.csv")
labelsF = c("Directo", "Email", "Referencias", "SEO", "Social Media", "Campañas", "Adwords")
Visitas_Por_Fuente$date <- as.Date(Visitas_Por_Fuente$date)
shinyServer(
function(input, output) {
output$VisitasFuente <- renderPlot({
# Filter the data based on user selection month
date_seq <- seq(input$dates[1], input$dates[2], by = "day")
VisitasData <- filter(Visitas_Por_Fuente, date %in% date_seq & Fuentes %in% labelsF)
VisitasData %>% group_by(Fuentes) %>%
summarise(sessions = sum(sessions))
ggplot(VisitasData, aes(factor(Fuentes), sessions, fill = Fuentes)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label = comma(sessions)), position=position_dodge(width=0.9), vjust=-0.25) +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9", "12", "15"),
labels = labelsF,
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#A082F8", "#F072A2"))
})
})
2) Then i use the same code, but not within shiny, just ggplot2 code:
ggplot(VisitasData, aes(factor(Fuentes), sessions, fill = Fuentes)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label = comma(sessions)), position=position_dodge(width=0.9), vjust=-0.25) +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9", "12", "15"),
labels = labelsF,
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#A082F8", "#F072A2"))
And get what i need:
I also tried, using a reactive function (as recommended in comments), but got:
Error : ggplot2 doesn't know how to deal with data of class reactive
Googled that and found:
http://stackoverflow.com/questions/27771691/many-error-signs-when-running-ggplot-in-render-plot-shiny-in-general
But now,prints a blank sheet:
This is my code with the reactive function:
function(input, output) {
dataSeq <- reactive({
date_seq <- seq(input$dates[1], input$dates[2], by = "day")
})
VisitasData <- reactive({
VisitasData <- filter(Visitas_Por_Fuente, date %in% dataSeq & Fuentes %in% labelsF)
VisitasData %>% group_by(Fuentes) %>%
summarise(sessions = sum(sessions))
})
output$VisitasFuente <- renderPlot({
# Bar graph using ggplot2 library
ggplot(ggplot(selectedData(VisitasData), aes(factor(VisitasData$Fuentes), VisitasData$sessions,
fill = Fuentes)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label = comma(sessions)), position=position_dodge(width=0.9), vjust=-0.25) +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9", "12", "15"),
labels = labelsF,
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#A082F8", "#F072A2"))
})
})
Assuming you want those numbers that showed up in your first call
Fuentes sessions
1 Adwords 71
2 Campa�as 280
3 Directo 11610
4 Email 437
5 Referencias 13143
6 SEO 39837
7 Social Media 5981
You just made a little mistake here:
VisitasData %>% group_by(Fuentes) %>%
summarise(sessions = sum(sessions))
You made a new dataframe, but you didn't assign it to anything. What you want is:
VisitasData <- VisitasData %>% group_by(Fuentes) %>%
summarise(sessions = sum(sessions))
Then you don't need to do a reactive thing, just used the code you did when you first posted it above.
library(ggplot2)
library(dplyr)
require(scales)
Visitas_Por_Fuente <- read.csv("D:\\RCoursera\\Movistar-App-2\\Visitas_Por_Fuente_Dic.csv")
labelsF = c("Directo", "Email", "Referencias", "SEO", "Social Media", "Campañas", "Adwords")
Visitas_Por_Fuente$date <- as.Date(Visitas_Por_Fuente$date)
shinyServer(
function(input, output) {
output$VisitasFuente <- renderPlot({
# Filter the data based on user selection month
date_seq <- seq(input$dates[1], input$dates[2], by = "day")
VisitasData <- filter(Visitas_Por_Fuente, date %in% date_seq & Fuentes %in% labelsF)
VisitasData <- VisitasData %>% group_by(Fuentes) %>%
summarise(sessions = sum(sessions))
# Bar graph using ggplot2 library
ggplot(VisitasData, aes(factor(Fuentes), sessions, fill = Fuentes)) +
geom_bar(stat="identity", position = "dodge") +
geom_text(aes(label = comma(sessions)), position=position_dodge(width=0.9), vjust=-0.25) +
scale_fill_manual(breaks = c("0", "1", "3", "6", "9", "12", "15"),
labels = labelsF,
values = c("#E69F00", "#56B4E9", "#009E73",
"#F0E442", "#0072B2", "#A082F8", "#F072A2"))
})
})
Is this what you intended?

Resources