How do you make a comparative stem and leaf plot in R? The data on one side is
c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 6.5, 7.0, 6.4, 7.9, 9.0,
8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
and the data on the other side is
c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0, 8.3, 7.8, 8.1, 7.4, 8.5,
8.9, 9.8, 9.7, 14.1, 12.6, 11.2)
I have already assigned each to either x[1] or x[2]. I have tried making two stem and leaf plots and then combining them but that does not work.
Have a look at stem.leaf.backback of the aplpack package. It sounds like that may be what you are looking for.
> a <- c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 6.5, 7.0, 6.4, 7.9, 9.0, 8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
> b <-c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0, 8.3, 7.8, 8.1, 7.4, 8.5, 8.9, 9.8, 9.7,14.1, 12.6, 11.2)
> stem.leaf.backback(a,b)
_________________________________
1 | 2: represents 1.2, leaf unit: 0.1
a b
_________________________________
| 5* |
1 9| 5. |8 1
3 43| 6* |1 2
6 885| 6. |6 3
11 43200| 7* |0124 7
(6) 988776| 7. |88 9
10 21| 8* |133 (3)
8 7| 8. |59 8
7 0| 9* |2 6
6 77| 9. |78 5
| 10* |
4 7| 10. |
3 3| 11* |2 3
2 86| 11. |
| 12* |
_________________________________
HI: 12.6
14.1
n: 27 20
_________________________________
Setting the m parameter to 1 gives:
> stem.leaf.backback(a,b,m=1)
___________________________________________
1 | 2: represents 1.2, leaf unit: 0.1
a b
___________________________________________
1 9| 5 |8 1
6 88543| 6 |16 3
(11) 98877643200| 7 |012488 9
10 721| 8 |13359 (5)
7 770| 9 |278 6
4 7| 10 |
3 863| 11 |2 3
| 12 |6 2
___________________________________________
HI: 14.1
n: 27 20
___________________________________________
The basic stem function has no support for this. It would be easier to do a histogram as #pbible pointed out (although, not much easier if you want them back to back). But you could do
#sample data
x<-list()
x[[1]]<-c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8,
6.5, 7.0, 6.4, 7.9, 9.0, 8.2, 8.7, 7.8, 9.7, 7.4, 7.7,
9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
x[[2]]<-c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0,
8.3, 7.8, 8.1, 7.4, 8.5, 8.9, 9.8, 9.7, 14.1, 12.6, 11.2)
#specify common breaks
brx <- pretty(range(unlist(x)),
n = nclass.Sturges(unlist(x)),min.n = 1)
#calculate bins
h1 = hist(x[[1]], breaks=brx, plot=FALSE)
h2 = hist(x[[2]], breaks=brx, plot=FALSE)
#draw
plot(NA,NA,type="n", xlab="", ylab="",
xlim=range(c(-h1$counts, h2$counts)),
ylim=range(brx),
xaxt="n"
)
rect(-h1$counts, brx[-1], 0, brx[-length(brx)], col="blue")
rect(0, brx[-1], h2$counts, brx[-length(brx)], col="red")
axis(1, at=axTicks(side=1), labels=abs(axTicks(side=1)))
which gives you
And if it really needs to be stem and leaf style, here's a fragile attempt
x<-list()
x[[1]]<-c(5.9, 7.2, 7.3, 6.3, 8.1, 6.8, 7.0, 7.6, 6.8, 6.5, 7.0, 6.4, 7.9, 9.0, 8.2, 8.7, 7.8, 9.7, 7.4, 7.7, 9.7, 7.8, 7.7, 11.6, 11.3, 11.8, 10.7)
x[[2]]<-c(6.1, 5.8, 7.8, 7.1, 7.2, 9.2, 6.6, 8.3, 7.0, 8.3, 7.8, 8.1, 7.4, 8.5, 8.9, 9.8, 9.7, 14.1, 12.6, 11.2)
X<-stack(setNames(x, c("a","b")))
brx <- pretty(range(X$values),
n = nclass.Sturges(X$values),min.n = 1)
X$stem <- factor(brx[cut(unlist(x), breaks=brx, include.lowest=T, labels=F)], levels=brx[-length(brx)])
X$leaf <- as.integer(X$values %% 1 *10)
max.leaf.width <- 2*with(aggregate(leaf~ind+stem, X, length), tapply(leaf, ind, max))
fmt<-paste0("%", max.leaf.width[1],"s | %2s | %-", max.leaf.width[2],"s")
va<-with(subset(X, ind=="a"), tapply(leaf, stem, function(x) paste(rev(sort(x)), collapse=" ")))
vb<-with(subset(X, ind=="b"), tapply(leaf, stem, function(x) paste(sort(x), collapse=" ")))
va[is.na(va)]<-""
vb[is.na(vb)]<-""
cat(paste(sprintf(fmt, va, levels(X$stem), vb), collapse="\n"), "\n")
Which produces
9 | 5 | 7
7 7 5 4 2 0 0 | 6 | 0 0 5
9 7 7 7 7 5 4 2 2 | 7 | 0 2 4 7 7
6 1 0 0 | 8 | 0 3 3 5 9
6 6 | 9 | 1 6 8
6 | 10 |
8 5 3 | 11 | 1
| 12 | 5
| 13 |
| 14 | 0
Related
I am trying to group a continuous value data into tertile. I am using the function quantile to do this. following is my code
dd$wbc_tert = with(dd,
cut(wbc,
vTert,
include.lowest = T,
labels = c("Low", "Medium", "High")))
Isn't it supposed to give equal count of values in each group? I am getting different count in the groups.
> dd %>% filter(wbc_tert == 'High') %>% select('wbc') %>% nrow()
[1] 143
> dd %>% filter(wbc_tert == 'Low') %>% select('wbc') %>% nrow()
[1] 148
> dd %>% filter(wbc_tert == 'Medium') %>% select('wbc') %>% nrow()
[1] 139
This is the dput of the values
c(10.9, 5.4, 9.1, 7.4, 6.6, 5.5, 4.4, 6.7, 7.8, 6.7, 6.6, 8.6,
8.4, 4.8, 7, 5.2, 7, 6.7, 10.4, 7.5, 8.5, 6.8, 8.5, 9.4, 4.6,
6.8, 10.2, 6.7, 4.6, 4.9, 6.7, 8.9, 5.9, 5.9, 9.9, 4.1, 8.4,
9, 7.7, 8.2, 5.7, 8.4, 7.7, 4.6, 6.5, 7.3, 4.9, 3.8, 6.2, 7.9,
5.3, 8.9, 6, 4.8, 5.9, 5.4, 8.6, 6.1, 9.5, 5.8, 6.2, 5.8, 7.9,
9.6, 6.6, 9.6, 7, 10.1, 9, 6.9, 9.1, 6.8, 8.4, 9.6, 4.4, 10.5,
7.9, 5.6, 5.1, 6.6, 6.5, 12.7, 5.3, 7.7, 4.8, 4.7, 6.1, 4.3,
6.1, 11.6, 5.9, 7.4, 5.7, 4.7, 4.8, 8.5, 5.6, 7.9, 9.1, 7.8,
5.3, 5, 8.1, 8.3, 4.7, 5.4, 7.6, 7.2, 5.7, 7.9, 7.9, 6.4, 3.8,
4.7, 6.2, 5, 7.6, 5.8, 5.4, 4.3, 6, 4.7, 6, 6.1, 5.8, 5.6, 4.7,
5, 11.5, 6.3, 4.4, 6.8, 6.6, 6.8, 6.1, 4.8, 5.4, 5.8, 5.2, 7.1,
5.4, 9.1, 6.9, 5.4, 8.5, 5.3, 7.3, 6.9, 9, 6.3, 8.4, 7.8, 5.7,
6.4, 5.3, 9.6, 6.4, 9.9, 8.9, 7.7, 6.2, 7.2, 4.6, 5.4, 4.6, 11.2,
3.1, 12.3, 5.9, 11.1, 6.2, 6.6, 4.1, 7.4, 9.4, 4.1, 6.7, 6.7,
6.1, 6.3, 5.6, NA, 3.7, 6.8, 6.7, 6.4, 7.3, 5.7, 6.7, 6.9, 5.7,
5.3, 4, 5.6, 4.8, 5.5, 6, 6.6, 3.6, 5.6, 8.9, 6.3, 5.8, 8.2,
8.6, 8.5, 5.7, 8.6, 6, 5.1, 5.7, 8.2, 5.4, 6.9, 6.9, 8.3, 9.5,
5.4, 10.2, 8.8, 7.2, 4.8, 9.8, 4.6, 6.3, 5.8, 4.9, 12.7, 7.5,
10.6, 9.3, 5.5, 10.7, 6.2, 9.3, 8.3, 7.8, 8.05, 9.57, 6.62, 6.21,
5.34, 6.11, 10.37, 4.45, 5.55, 8.05, 8.31, 5.06, 6.05, 4.76,
9.09, 9.11, 9.04, 6.99, 6.33, 9.47, 6.48, 4.46, 9.44, 6.88, 7.09,
5.75, 10.89, 6.68, 3.64, 6.55, 8.69, 5.89, 9.05, 6.38, 11.62,
9.11, 9.22, 7.97, 9.64, 12.76, 8.39, 6.57, 8.1, 7.3, 10.1, 4.7,
6.4, 7.2, 5.5, 3.7, 5.1, 9.8, 7.6, 7.7, 6, 3.9, 6.8, 5.4, 5.4,
9.7, 9, 6, 7.3, 6.3, 5.8, 8.3, 7, 4.1, 11.2, 5, 7.6, 6.5, 4.8,
8, 10.1, 7.1, 7.4, 4.3, 4, 10.12, 4.3, 7.26, 8.84, 8.44, 8.44,
8.12, 6.5, 8.58, 8.55, 8.82, 4.53, 9.51, 4.93, 4.42, 4.69, 8.69,
5.77, 3.37, 6.58, 3.72, 3.09, 7.13, 8.11, 7.2, 12.18, 6.52, 7.91,
5.69, 8.24, 7.67, 5.69, 4.85, 7.03, 4.16, 3.57, 8.1, 4.61, 5.98,
5.13, 7.68, 5.47, 5.54, 4.59, 6, 11.62, 7.38, 7.06, 8.74, 8.02,
6.73, 7.19, 6.36, 4.86, 6.55, 8.4, 7.76, 4.73, 4.8, 5.73, 8.53,
4.6, 7.96, 9.48, 6.59, 5.75, 6.61, 6.49, 7.91, 6.92, 7.14, 6.24,
12.53, 7.03, 4.73, 8.05, 7.26, 4.07, 6.7, 5.7, 7.39, 5.2, 6.61,
6.8, 6.77, 5.65, 6.08, 7.24, 6.13, 7.92, 7.37, 7.99, 3.31, 9.72,
8.71, 8.35, 5.05, 8.15, 5.1, 5.4, 8.8, 4.9, 5, 7.43, 10.3, 6.3,
9.5, 6.9, 6.7, 5.4, 7.7, 8, 6.5, 5.6, 9.7)
Can someone please help what could be the reason
Here is an example that shows that quantiles are not necessarily symmetric in the number of values.
# Define some data
x <- 1:10
y <- rep(1:2, 10)
# Look at the quantiles
quantile(x)
#> 0% 25% 50% 75% 100%
#> 1.00 3.25 5.50 7.75 10.00
# Due to the added y we now have asymmetry in sizes
quantile(c(y,x))
#> 0% 25% 50% 75% 100%
#> 1.00 1.00 2.00 2.75 10.00
# Notice how the number of values below 50 % and 75 % changes.
## Without y we get roughly the same bin size
sum(x<quantile(x, .5))
#> [1] 5
sum(x<quantile(x, .75))
#> [1] 7
## But when we add y, there is a doubling of values despite we only increase
## the percentile with 25 %
sum(c(y,x)<quantile(c(y,x), .5))
#> [1] 11
sum(c(y,x)<quantile(c(y,x), .75))
#> [1] 22
Created on 2022-08-18 by the reprex package (v2.0.1)
There are 9 ways to compute the quantiles with function quantile, the default is type = 7.
Use findInterval instead of cut.
vTert <- quantile(dd$wbc, (0:3)/3, na.rm = TRUE)
dd$wbc_tert <- findInterval(dd$wbc, vTert, rightmost.closed = TRUE, all.inside = TRUE)
dd$wbc_tert <- factor(dd$wbc_tert, labels = c("Low", "Medium", "High"))
table(dd$wbc_tert, useNA = "always")
#>
#> Low Medium High <NA>
#> 143 143 144 1
Created on 2022-08-18 by the reprex package (v2.0.1)
Hi I have a question some of you could help me out.
My vector is temperature collected hourly:
a<-c(7.95, 7.8, 7.85, 7.6, 7.1, 5.55, 4.35, 4.1, 7.35, 10.7, 14.2,
17.25, 19.1, 19.8, 20.1, 20.15, 19.9, 18.95, 16.7, 14.4, 13.75,
12.1, 12.3, 11.4, 10.3, 8.55, 7.45, 7.05, 5.6, 5.95, 4.85, 5.3,
9.35, 12.7, 16.15, 19.1, 20.5, 21.05, 21.4, 21.4, 21.35, 20.1,
16.95, 15.8, 15.6, 14.95, 14.15, 13.85)
I want to determine how many events there are which a is above 20 and below 10 for a certain period of time.
Pictorially, this is what I am looking for. Here there are two events (blue and green) where temperature amplitude threshold was achieved. Result should be 2.
============
Another example:
Here temperature was below 10 & above 20 for at least 1 hour, two times (or two events).
Result should be 2.
Data for example 2:
b<-c(20.2, 20.55, 20.85, 21.7, 20.7, 18.7, 17.5, 17.4, 16.65, 17.15,
15.8, 13.85, 12.55, 11.45, 10.2, 9.3, 8.2, 7.4, 7.25, 6.65, 5.9,
4.75, 4.5, 4.15, 4.4, 6.25, 8.1, 10.35, 12.4, 14.3, 15.3, 16.3,
17.25, 17.25, 16.85, 14.45, 12.85, 11.35, 10.2, 9.1, 8.6, 7.35,
5.9, 4.85, 3.65, 3.3, 2.95, 2.65, 2.45, 4.85, 6.45, 8.25, 9.95,
11.1, 12.3, 13.2, 13.95, 14.05, 13.15, 10.35, 8.15, 6.6, 6.3,
6, 7.55, 5.85, 5.05, 4.75, 4.5, 4.75, 4.75, 4.55, 5.15, 8.45,
12.05, 16.35, 18.9, 20.55, 21.6, 21.45, 21.75, 21.15, 20.05,
17.75, 16.5, 18.2, 18.05, 17.95, 17.8, 17.55, 17.25, 16.95, 16.6,
16.35, 16.1, 16.25, 16.4, 17.1, 17.8)
I update my answer using your new example b. I found a solution based on: Find a numeric pattern R .
# Get out of range (10,20)
x = ifelse(b<=10,1,0) # Don't need nested ifelse
# Specify if 2 for upper limit [20,inf)
x[b>=20]=2
z = rle(x)
> z
Run Length Encoding
lengths: int [1:10] 5 10 12 12 14 7 14 3 6 16
values : num [1:10] 2 0 1 0 1 0 1 0 2 0
Like your plot, there is two combinations of going lower limit to upper limit or the other way round: 2-0-1 or 1-0-2. You can do:
ranges = z$values
# This line looks for 0 -groups of T in range (10,20)- and the looks if the group before is 1 and the next 2 (low to up) or 2 and 1 (up to low)
x = as.integer(ranges == 0 & ( (lag(ranges)==2 & lead(ranges)==1) | (lag(ranges)==1 & lead(ranges)==2) ) )
x
[1] 0 1 0 0 0 0 0 1 0 NA
You can sum, omitting the NAs, to return 2:
sum(x, na.rm=TRUE)
You could remove 0s and just look for 1 followed by 2 or the other way round but it is the same concept. If you want to keep the z$lengths to work with them later, you could transform rle() output to a dataframe and adapt the code to mutate a new column.
Please, can anyone explain to me how to put this split data (Fibre) into a dataframe in r. So that I can have two columns: Group and Observation.
Fibre
[[1]]
12.5, 5, 4.5, 6, 10.2, 9.6, 15.5, 12.2, 13, 17.5, 13, 14
[[2]]
11.5, 7, 4.5, 8, 13.2, 19.6, 13.5, 15.2, 13.5, 20,17
[[3]]
10.5, 6, 8.5, 8, 11.2, 14.6, 19.5, 15.9, 14.5, 21,12,15,17,18
[[4]]
9.5, 16, 9.5, 8.5, 13.5, 12.6, 11.5, 16.7, 14, 19.5
I used:
NewData <- as.data.frame(Fibre)
I have a data frame that consists of 2000 rows and three columns. The columns are for Subject ID #, IV, and DV. There are 50 participants in the data (Subject #s 1:50), each with 40 separate observations (so 40 rows per participant).
I'd like to find the intercept and slope for each of the individual participants, but rather than manually running 50 lm's, I'm trying to figure out a way to accomplish this using a for loop.
To keep things simple, here's a condensed version of the data (I'm just doing 5 rows for 3 participants, rather than producing the full 2000 rows).
Having no idea what I'm doing when it comes to for loops, this is the last thing I tried.
Note: I've recreated a smaller version of the data below. Basically I'd like to make a for loop that runs an lm of the dv on the iv for each of the four participants in the example data frame, so that I can find the intercept and slope for each individual participant (rather than aggregating everything).
df <- data.frame(
id = rep(1:4, each=5),
iv = c(5.0, 3.6, 3.4, 4.5, 4.6, 7.8, 7.2, 10.8, 7.7, 8.7, 7.6, 6.8,
6.2, 5.6, 4.6, 6.7, 6.6, 6.3, 7.0, 5.1),
dv = c(6.50, 8.50, 8.00, 10.00, 10.00, 3.50, 10.00, 7.25, 2.50, 6.50,
10.00, 8.75, 10.00, 9.75, 10.00, 7.75, 7.75, 7.50, 8.75, 5.75)
)
for (i in 1:4)
{
m3 <- lm(df$dv ~ df$iv, data=df$id[[i]])
}
Not a for-loop but definitely a more concise R-centric way of going about things. broom::tidy() just takes the output from lm() and puts it into an easy to handle data frame.
EDIT: If you want it in one data.frame and be able to distinguish across ID's you can use the updated code below. I believe do() is deprecated or no longer the supported method to manipulate functions.
library(tidyverse)
library(broom)
df <- data.frame(
id = rep(1:4, each=5),
iv = c(5.0, 3.6, 3.4, 4.5, 4.6, 7.8, 7.2, 10.8, 7.7, 8.7, 7.6, 6.8,
6.2, 5.6, 4.6, 6.7, 6.6, 6.3, 7.0, 5.1),
dv = c(6.50, 8.50, 8.00, 10.00, 10.00, 3.50, 10.00, 7.25, 2.50, 6.50,
10.00, 8.75, 10.00, 9.75, 10.00, 7.75, 7.75, 7.50, 8.75, 5.75)
)
df %>%
group_split(id) %>%
map_df(~ lm(dv ~ iv, data = .) %>%
tidy() %>%
mutate(id = unique(.x$id))
)
#> # A tibble: 8 x 6
#> term estimate std.error statistic p.value id
#> <chr> <dbl> <dbl> <dbl> <dbl> <int>
#> 1 (Intercept) 8.96 5.28 1.70 0.188 1
#> 2 iv -0.0847 1.24 -0.0684 0.950 1
#> 3 (Intercept) 3.55 10.3 0.344 0.753 2
#> 4 iv 0.284 1.21 0.235 0.829 2
#> 5 (Intercept) 10.5 1.65 6.36 0.00786 3
#> 6 iv -0.126 0.264 -0.478 0.665 3
#> 7 (Intercept) -1.69 1.06 -1.59 0.210 4
#> 8 iv 1.45 0.167 8.69 0.00321 4
Created on 2019-02-22 by the reprex package (v0.2.1)
I approach this kind of grouped regression by combining group_by() and do().
While #dylanjm has provided a nice concise method using map() and broom() to produce a list of tibbles containing model outputs, this alternative might be handy if you want a single df with two columns listing all of your intercepts & slopes.
library(dplyr)
df <- data.frame(id = rep(1:4, each=5),
iv = c(5.0, 3.6, 3.4, 4.5, 4.6, 7.8, 7.2, 10.8, 7.7, 8.7, 7.6, 6.8,
6.2, 5.6, 4.6, 6.7, 6.6, 6.3, 7.0, 5.1),
dv = c(6.50, 8.50, 8.00, 10.00, 10.00, 3.50, 10.00, 7.25, 2.50, 6.50,
10.00, 8.75, 10.00, 9.75, 10.00, 7.75, 7.75, 7.50, 8.75, 5.75))
#This will segment obs by the `id` variable, & run a separate lm for each of the segments.
df_lms<- df %>%
group_by(id)%>%
do(mod = lm(dv ~ iv, data=.))
#This will give you a dataframe with a column for intercepts, and a column for slopes.
cbind(df_lms %>% do(data.frame(intc = coef(.$mod)[1])),
df_lms %>% do(data.frame(slope = coef(.$mod)[2])))
I´m working on a leaflet map in r that visualizes data from a survey onto the map. You can get a look of how it looked over here: https://maglin.shinyapps.io/UM33/ . As you can see if you click on an area you get the name of thea area and the median score on the various questions in Swedish, for example this...
>! Område: Eds Glesbygd
Fler kultur och fritidsaktiviteter för äldre : 7.9
Fler kultur och fritidsaktiviteter för barn och ungdomar : 8.7
Förbättra äldreomsorgen i kommunen : 8.9
Fler ungdomsgårdar och fältassistenter : 9
Minska barngrupperna i förskolan : 9.9
But after some changes in the program I get this instead...
>!Område: 1:43
Bevara existerande större grönområden : c(5, 9.4, 9.6, 10.4, 8.7, 10.8, 8, 9.8, 7.3, 9.7, 12, 9, 10.1, 9.3, 9.4, 9.7, 8.5, 9.7, 10, 1, 8.4, 9.1, 10.2, 6.2, 8, 10.1, 11.5, 10.8, 9.7, 8.7, 10.3, 9.6, 10.6, 10.9, 10.9, 10, 10.7, 8, 9.4, 10.9, 6, 9.6, 14)
Anlägga parker i existerande stadsdelar : c(8, 8.1, 9.1, 9.4, 7.1, 9.6, 7.8, 9.4, 7.2, 7.4, 9, 8.2, 6.7, 8.4, 9, 9, 8.6, 8, 8, 3, 7.8, 7.8, 8, 5.2, 6.7, 8.1, 8.2, 8.9, 7.5, 7.3, 8.8, 7.7, 7.8, 7.5, 7.8, 10, 8.2, 5.7, 7.8, 7, 8, 8.2, 7)
Bygga bostäder nära grönområden : c(11, 7.7, 8.3, 6.9, 7.3, 6.6, 5.2, 7.6, 8.5, 7.5, 7.5, 7.4, 7.5, 8.7, 7.3, 11.3, 8.2, 8, 9, 13, 6.8, 6.7, 8, 9.2, 11, 7.2, 5.8, 7.5, 6.3, 8.3, 7.6, 8.1, 8.4, 9.1, 7.5, 13, 7.3, 11, 8.6, 5.9, 9, 7.3, 7)
Rusta upp befintliga parker : c(6, 9.4, 9.6, 10.7, 8.1, 9.9, 8.8, 8.8, 6.9, 9.5, 9, 9.1, 9.9, 8.3, 8.9, 11, 9.9, 9.7, 6, 12, 8.8, 9.4, 9.3, 9.5, 10, 9, 8.9, 9.6, 9.6, 8.5, 9.2, 8.5, 9.2, 9.3, 9, 14, 9.9, 9.7, 9.3, 10.3, 6, 9.7, 7)
Skapa bättre tillgänglighet till större grönområden : c(7, 8.1, 8.7, 9.2, 8.1, 9.1, 7.4, 8.5, 8.5, 8, 9.5, 7.2, 8.6, 7.6, 7.9, 8, 7, 8.7, 9, 13, 7.2, 7.3, 9, 6.2, 8.3, 8.5, 8.4, 9.1, 8.2, 7, 8.9, 8.2, 7.8, 7.8, 8, 13, 8.7, 9, 8.2, 8.4, 8, 8.3, 7)
The popup seems to show all the medians for every area instead of just the one you clicked on. This is an example of how the data looks when I save it inside an reactive variable...
Area X1a X1b X1c X1d X1e favorit
(fctr) (dbl) (dbl) (dbl) (dbl) (dbl) (chr)
1 Antuna /Älvsunda 5.0 8.0 11.0 6.0 7.0 X1c
2 Brunnby/Vik 9.4 8.1 7.7 9.4 8.1 X1a
3 Carlslund/Brunnby Park 9.6 9.1 8.3 9.6 8.7 X1a
4 Dragonvägen 10.4 9.4 6.9 10.7 9.2 X1d
5 Eds Glesbygd 8.7 7.1 7.3 8.1 8.1 X1a
And this is how the data looks when I print it out just before it gets feed into the addPolygons(popup) function...
>!"<Strong>Område: </strong> 1:43 <br><Strong> Bevara existerande större grönområden :</strong> c(5, 9.4, 9.6, 10.4, 8.7, 10.8, 8, 9.8, 7.3, 9.7, 12, 9, 10.1, 9.3, 9.4, 9.7, 8.5, 9.7, 10, 1, 8.4, 9.1, 10.2, 6.2, 8, 10.1, 11.5, 10.8, 9.7, 8.7, 10.3, 9.6, 10.6, 10.9, 10.9, 10, 10.7, 8, 9.4, 10.9, 6, 9.6, 14) <br><strong> Anlägga parker i existerande stadsdelar :</strong> c(8, 8.1, 9.1, 9.4, 7.1, 9.6, 7.8, 9.4, 7.2, 7.4, 9, 8.2, 6.7, 8.4, 9, 9, 8.6, 8, 8, 3, 7.8, 7.8, 8, 5.2, 6.7, 8.1, 8.2, 8.9, 7.5, 7.3, 8.8, 7.7, 7.8, 7.5, 7.8, 10, 8.2, 5.7, 7.8, 7, 8, 8.2, 7) <br><strong> Bygga bostäder nära grönområden :</strong> c(11, 7.7, 8.3, 6.9, 7.3, 6.6, 5.2, 7.6, 8.5, 7.5, 7.5, 7.4, 7.5, 8.7, 7.3, 11.3, 8.2, 8, 9, 13, 6.8, 6.7, 8, 9.2, 11, 7.2, 5.8, 7.5, 6.3, 8.3, 7.6, 8.1, 8.4, 9.1, 7.5, 13, 7.3, 11, 8.6, 5.9, 9, 7.3, 7) <br><strong> Rusta upp befintliga parker :</strong> c(6, 9.4, 9.6, 10.7, 8.1, 9.9, 8.8, 8.8, 6.9, 9.5, 9, 9.1, 9.9, 8.3, 8.9, 11, 9.9, 9.7, 6, 12, 8.8, 9.4, 9.3, 9.5, 10, 9, 8.9, 9.6, 9.6, 8.5, 9.2, 8.5, 9.2, 9.3, 9, 14, 9.9, 9.7, 9.3, 10.3, 6, 9.7, 7) <br><strong> Skapa bättre tillgänglighet till större grönområden :</strong> c(7, 8.1, 8.7, 9.2, 8.1, 9.1, 7.4, 8.5, 8.5, 8, 9.5, 7.2, 8.6, 7.6, 7.9, 8, 7, 8.7, 9, 13, 7.2, 7.3, 9, 6.2, 8.3, 8.5, 8.4, 9.1, 8.2, 7, 8.9, 8.2, 7.8, 7.8, 8, 13, 8.7, 9, 8.2, 8.4, 8, 8.3, 7)"
Has the dataset been turned into a factor or something? I can supply more code if needed, but I didn´t want to spam the OP with to much, The spoiler functions is messing with me.
EDIT1: So I have setup a project based on an old version that works and started looking for differences between the two projects. One difference so far is that there is a slight difference in the variable that is used to build the popup output...
In my current(faulty) project, this is what you get when you print out the variable
>print(var)
Source: local data frame [43 x 7]
Area X1a X1b X1c X1d X1e favorit
(fctr) (dbl) (dbl) (dbl) (dbl) (dbl) (chr)
1 Antuna /Älvsunda 5 8 11 6 7 X1c
2 Brunnby/Vik 9 8 8 9 8 X1a
3 Carlslund/Brunnby Park 10 9 8 10 9 X1a
4 Dragonvägen 10 9 7 11 9 X1d
5 Eds Glesbygd 9 7 7 8 8 X1a
.. ... ... ... ... ... ... ...
In the older but working version the variable looks like this...
>print(var)
Area X1a X1b X1c X1d X1e favorit
1 Antuna /Älvsunda 5 8 11 6 7 X1c
2 Brunnby/Vik 9 8 8 9 8 X1a
3 Carlslund/Brunnby Park 10 9 8 10 9 X1a
4 Dragonvägen 10 9 7 11 9 X1d
5 Eds Glesbygd 9 7 7 8 8 X1a
Have I accidentally changed a file/object type here that makes scrambles things up?
Edit2: I seem to have solved the problem by saving the dataset that (var) reads from in .csv format and then reading it in again, Any got a clue why that works?
Edit3: Seems the change happens when I call the plyr rename function, that seems to garble the output.