Box plot containing multiple variables? / Violin plot? - r
I'm pretty new to R and struggling to get my box plot to include all the individual's variables in one graph. The data is looking at site locations used by 3 different species. So far I can only get it to work within a bar graph, which isn't ideal.
If possible, would anyone know how to do this also as a violin plot?
below is my code and current attempts.
> str(pips)
'data.frame': 732 obs. of 8 variables:
$ Site : Factor w/ 4 levels "Allerthorpe",..: 4 4 4 4 4 4 4 4 4 4 ..
$ Box.Type : Factor w/ 4 levels "Combi","Standard",..: 2 2 2 2 2 2 2 2 2 2 ..
$ Size : Factor w/ 4 levels "Large Woodcrete",..: 4 4 4 4 4 4 4 4 4 4 ...
$ Species : Factor w/ 3 levels "P. nathusii",..: 2 2 2 2 2 2 2 2 2 2 ...
$ No..Bats : int 1 4 1 3 1 3 3 2 1 2 ...
barplot(xtabs(No..Bats~Species + Site, data=pips),
legend=c("P. nathusii", "P. pipistrellus", "P. pygmaeus")
EDIT. I have now managed to create a violin plot. However I am still needing to adjust my box plot.
Dataset is Below (I wasnt sure how to post this)
> dput(pips)
structure(list(Site = structure(c(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, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 1L, 1L, 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,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L, 1L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 7L, 2L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 12L, 4L, 1L, 2L, 6L, 3L, 1L, 6L, 10L, 6L, 4L, 6L, 4L,
10L, 11L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 3L, 2L, 3L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 4L, 5L, 1L, 1L, 1L, 5L, 1L,
3L, 1L, 1L, 8L, 1L, 3L, 1L, 3L, 1L, 1L, 1L, 3L, 1L, 1L, 1L,
1L, 2L, 1L, 3L, 4L, 2L, 2L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L,
5L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L,
2L, 1L, 3L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 5L,
1L, 7L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L,
1L, 1L, 3L, 2L, 1L, 3L)), class = "data.frame", row.names = c(NA,
-732L))
Generated some example data. In ggplot, you can use the geom_violin.
set.seed(1)
df <- data.frame(letters=sample(c(rep(c('a','b','c'), 400))),
numbers=sample(c(rep(c(1:4), 300))),
value=sample(1:10, 1200, replace=T))
require(ggplot2)
ggplot(data = df, aes(x=letters, y=value)) +
geom_violin() +
facet_grid(.~numbers)
If you don't mind ggplot graphics, this might be what you are looking for.
First I will make up a dataset, since you have not posted one.
set.seed(4890) # Make the results reproducible
n <- 732
pips <- data.frame(Site = sample(LETTERS[1:4], n, TRUE),
Species = sample(letters[1:3], n, TRUE),
No = sample.int(20, n, TRUE))
Now the graph.
library(ggplot2)
ggplot(pips, aes(Species, No, fill = Species)) +
geom_boxplot() +
scale_fill_grey() +
facet_grid(cols = vars(Site)) +
theme_bw()
With the datset you have posted, I have made a small change to the above code. The x axis labels would be over each other, so I added a call to theme(axis.text.x) and rotated them 45 degrees.
ggplot(pips, aes(x = Species, y = `No..Bats`, fill = Species)) +
geom_boxplot() +
scale_fill_grey() +
facet_grid(cols = vars(Site)) +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Related
ggplot2 select categories for bar chart and create labels
I am trying make bar chart with ggplot2 with the dataset below. When I use the code ggplot(p.data, aes(x = `Period Number`, y = `Total Jumps`)) + stat_summary(data = subset(p.data, Status = "Starter"), fun ="mean", geom = "bar") I get this graph: The most concerning aspect is the for period 2, 3, 4, and 5 the bars should be taller (period 2 should be around 9.9). Additionally, I would like to remove period 0 and period 1 and add bar labels with the raw data and without creating an additional data frame. p.data <- structure(list(`Period Number` = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), `Total Jumps` = c(112L, 97L, 28L, 132L, 162L, 19L, 92L, 112L, 97L, 141L, 68L, 86L, 76L, 26L, 105L, 125L, 19L, 92L, 112L, 64L, 101L, 68L, 4L, 8L, 0L, 8L, 12L, 0L, 0L, 0L, 13L, 8L, 0L, 8L, 2L, 2L, 5L, 12L, 0L, 0L, 0L, 5L, 11L, 0L, 0L, 6L, 0L, 9L, 8L, 0L, 0L, 0L, 7L, 10L, 0L, 14L, 5L, 0L, 5L, 5L, 0L, 0L, 0L, 8L, 11L, 0L, 108L, 131L, 47L, 136L, 159L, 35L, 114L, 116L, 111L, 190L, 64L, 75L, 95L, 47L, 116L, 123L, 27L, 103L, 108L, 70L, 152L, 64L, 4L, 7L, 0L, 14L, 10L, 0L, 0L, 0L, 15L, 10L, 0L, 4L, 0L, 0L, 3L, 7L, 7L, 8L, 8L, 5L, 10L, 0L, 7L, 14L, 0L, 3L, 10L, 1L, 0L, 0L, 11L, 7L, 0L, 18L, 15L, 0L, 0L, 9L, 0L, 3L, 0L, 10L, 11L, 0L, 118L, 96L, 48L, 143L, 170L, 37L, 118L, 117L, 116L, 165L, 56L, 80L, 68L, 48L, 114L, 130L, 36L, 114L, 107L, 80L, 123L, 56L, 2L, 10L, 0L, 8L, 11L, 0L, 0L, 0L, 5L, 9L, 0L, 4L, 12L, 0L, 6L, 5L, 0L, 4L, 8L, 12L, 8L, 0L, 7L, 4L, 0L, 10L, 10L, 0L, 0L, 0L, 12L, 13L, 0L, 25L, 2L, 0L, 5L, 14L, 1L, 0L, 2L, 7L, 12L, 0L), Status = structure(c(1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 1L), .Label = c("Bench", "Starter"), class = "factor")), row.names = c(NA, 198L), class = "data.frame") Thank you for your help!
It's best to pass that data you actually want to plot to the plotting function, rather than trying to coerce it within the plotting function. In this case you were trying to subset a different data frame from the one you passed to ggplot inside stat_summary. The call to ggplot had already set up the aesthetics you wanted mapped, then in your only geom layer, you were telling ggplot you wanted a completely different set of aesthetics. You don't need to create another data frame to reshape your data. Here's how you could do it using dplyr: library(dplyr) library(ggplot2) p.data %>% filter(Status == "Starter") %>% group_by(`Period Number`) %>% summarise(`Total Jumps` = mean(`Total Jumps`)) %>% filter(`Period Number` > 1) %>% ggplot(aes(x = `Period Number`, y = `Total Jumps`)) + geom_col(fill = "dodgerblue", colour = "black") + geom_text(aes(y = `Total Jumps` + 1, label = signif(`Total Jumps`, 2)))
How to color outline differently from fill in histogram using ggplot / R? [duplicate]
This question already has an answer here: Manually colouring plots with `scale_fill_manual` in ggplot2 not working (1 answer) Closed 3 years ago. Please find My data q below I have produced the following plot: By using the script: library(tidyverse) w %>% as_tibble() %>% mutate(Studie=as.character(Studie), best.resp =as.factor(best.resp)) %>% bind_rows(., mutate(., Studie="all")) %>% count(Studie, best.resp) %>% ggplot(aes(Studie, n, fill= best.resp)) + scale_fill_manual(values = c("green", "purple", "yellow")) + scale_colour_manual(values = c("blue", "red","orange")) + geom_col(position = position_dodge2(preserve = "single", padding = 0)) I want the outline around each bar to have one set of colors while the fill to have another set of colors. As you can see, I tried using scale_fill_manual and scale_colour_manual, however, that does not solve my problem. I have attached a picture illustrating what I mean by outlines having one color and the fill another color: My data q <- structure(list(Studie = 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, 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, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), best.resp = c(0L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 2L, 0L, 2L)), .Names = c("Studie", "best.resp"), class = "data.frame", row.names = c(NA, -106L))
You need to map a variable to the colour aesthetic (in aes): ggplot(aes(Studie, n, fill= best.resp, colour = best.resp)
I think in your code you have a w %>% is it supposed to be q? You need to specify color in your aes command. Right now, you just have the fill-- so the scale color manual later, doesn't apply to anything. q %>% as_tibble() %>% mutate(Studie=as.character(Studie), best.resp =as.factor(best.resp)) %>% bind_rows(., mutate(., Studie="all")) %>% count(Studie, best.resp) %>% ggplot(aes(Studie, n, color = best.resp, fill= best.resp)) + scale_fill_manual(values = c("green", "purple", "yellow")) + scale_colour_manual(values = c("blue", "red","orange")) + geom_col(position = position_dodge2(preserve = "single", padding = 0))
How to plot predictions of binomial GLM that has both continuous and categorical variables
I have a binomial GLM in R, with several predictors that are both continuous and categorical. The response variable is "Presence", which is binary (0/1). Length is a continuous variable, while all others are categorical. I am trying to plot predictions for each of the variables in the final model, particularly for "length", but I'm having difficulties. My data are the following: MyData<-structure(list(site = structure(c(3L, 1L, 3L, 2L, 1L, 4L, 3L, 4L, 1L, 2L, 4L, 5L, 5L, 1L, 4L, 3L, 2L, 4L, 1L, 4L, 5L, 1L, 5L, 4L, 3L, 1L, 3L, 5L, 5L, 4L, 4L, 3L, 1L, 5L, 1L, 3L, 1L, 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L, 4L, 3L, 4L, 4L, 4L, 3L, 3L, 4L, 1L, 4L, 3L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 4L, 1L, 3L, 3L, 4L, 4L, 4L, 2L, 4L, 3L, 3L, 4L, 3L, 4L, 4L, 3L, 4L, 3L, 3L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 1L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 3L, 2L, 3L, 1L, 2L, 5L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 2L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 3L, 1L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 4L, 4L, 4L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 4L, 4L, 3L, 4L, 2L, 3L, 4L, 4L, 2L, 3L, 2L, 4L, 4L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 4L, 3L, 4L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 3L, 4L, 2L, 5L, 3L, 4L, 2L, 4L, 4L, 4L, 3L, 3L, 3L, 4L, 4L, 2L, 4L, 3L, 4L, 4L, 3L, 4L, 4L, 4L, 3L, 2L, 4L), .Label = c("East", "Flat", "North", "South", "West"), class = "factor"), length = c(260L, 60L, 60L, 40L, 240L, 80L, 30L, 100L, 100L, 200L, 70L, 50L, 60L, 35L, 120L, 60L, 500L, 40L, 20L, 70L, 250L, 80L, 50L, 130L, 350L, 170L, 50L, 60L, 90L, 50L, 40L, 110L, 60L, 70L, 70L, 500L, 140L, 50L, 50L, 360L, 50L, 150L, 60L, 270L, 280L, 130L, 130L, 50L, 60L, 30L, 70L, 70L, 60L, 400L, 20L, 30L, 70L, 160L, 340L, 100L, 210L, 60L, 70L, 130L, 50L, 40L, 50L, 80L, 390L, 40L, 110L, 130L, 40L, 230L, 120L, 70L, 80L, 80L, 90L, 70L, 150L, 120L, 50L, 100L, 120L, 10L, 40L, 80L, 180L, 160L, 200L, 40L, 70L, 90L, 50L, 40L, 80L, 80L, 70L, 480L, 90L, 60L, 100L, 140L, 190L, 20L, 70L, 360L, 70L, 130L, 60L, 50L, 320L, 210L, 130L, 180L, 90L, 20L, 300L, 90L, 50L, 130L, 70L, 70L, 40L, 40L, 50L, 40L, 100L, 20L, 70L, 100L, 340L, 70L, 110L, 40L, 230L, 200L, 80L, 35L, 110L, 200L, 50L, 110L, 100L, 50L, 150L, 110L, 50L, 50L, 40L, 70L, 80L, 60L, 100L, 90L, 40L, 300L, 140L, 180L, 140L, 40L, 190L, 100L, 170L, 40L, 120L, 15L, 70L, 340L, 40L, 40L, 70L, 60L, 130L, 140L, 170L, 120L, 90L, 130L, 210L, 50L, 180L, 120L, 100L, 50L, 90L, 70L, 360L, 80L, 30L, 170L, 70L, 300L, 40L, 130L, 120L, 90L, 40L, 40L, 140L, 80L, 400L, 70L, 80L, 60L, 420L, 320L, 200L, 40L, 50L, 70L, 50L, 80L, 50L, 110L, 100L, 120L, 170L, 20L, 110L, 20L, 20L, 30L, 30L, 90L, 150L, 80L, 40L, 90L, 300L, 30L, 70L, 50L, 90L, 200L ), sun = structure(c(1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 2L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 1L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 3L, 3L, 2L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 3L, 3L, 1L, 2L, 1L, 1L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 3L, 1L, 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0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 1L, 0L, 1L, 0L )), .Names = c("site", "species", "aspect", "length", "sun", "leaf", "Presence"), row.names = c(NA, 236L), class = "data.frame") (note that this is a reduced dataset, and I have already removed variables that were dropped during model selection) The optimal model is: model <- glm(Presence ~ site + species + aspect + length + sun + leaf, data=MyData, family=binomial) I tried the following, but it wants the other variables too, so I get an error: plot(MyData$length, MyData$Presence) mydat1 <- data.frame(length = seq(from = 10, to = 500, by = 1) pred1 <- predict(model, newdata = mydat1, type = "response") lines(MyData$length, pred1) So I tried specifying all variables, but then it only puts a horizontal line through the presence data points (and that means I need to specify all possible combinations of factor variables I suppose): plot(MyData$length, MyData$Presence) mydat2 <- data.frame(length = seq(from = 10, to = 500, by = 1), site = "R1a", species = "Monogyna", aspect = "Flat", sun = "Sun", leaf = "Scarce") pred2 <- predict(model, newdata = mydat2, type = "response") lines(MyData$length, pred2) Finally, I tried the following code: pred <- predict(model, type = "response") par(mfrow=c(2,2)) for(i in names(MyData)){ plot(MyData[,i],pred,xlab=i, ylab="Probability") } I am confused by this last one, as I am not able to obtain the curve, plus the output gives me predicted values for variables that are not even in the optimal model. What I should expect under this model, is a sinusoidal curve, I suppose. But that's not what I'm getting. How can I produce a meaningful plot of predictions? Any help would be greatly appreciated.
I would use the effects package for some easier results for a single predictor. Here is how: library(effects) fit <- as.data.frame(effect('length', model, xlevels = 100)) Plotting is easy (although note the overplotting): plot(MyData$length, MyData$Presence) lines(fit$length, fit$fit) Or we can use ggplot2: library(ggplot2) ggplot() + geom_count(aes(length, Presence), MyData) + geom_line(aes(length, fit), fit, size = 1, col = 'red') + geom_ribbon(aes(length, ymin = lower, ymax = upper), fit, alpha = 0.15) + scale_size_area() We can see that the effect of length is not very impressive.
Replace numbers with Boolean in r
I want to use weka to predict future instances. I have a csv file and a small portion of it is as following: I used r to read the file but I am not sure how to substitute the zeros with "No error" and anything besides zero to "Error". I would have left like this but unfortunately weka is not able to predict instances with numbers as the status. Edit 2: I tried your solution and even though it changed the numbbers to error/no error, it erased the other columns. Did I do something wrong? I also wrote it to a file so it would be easier to see. Edit 3: dput(data) structure(list(BoxType = structure(c(3L, 3L, 6L, 6L, 3L, 8L, 3L, 3L, 6L, 4L, 4L, 3L, 3L, 4L, 6L, 6L, 3L, 6L, 2L, 4L, 3L, 3L, 8L, 3L, 6L, 8L, 2L, 3L, 8L, 8L, 3L, 8L, 2L, 2L, 8L, 8L, 2L, 3L, 8L, 3L, 4L, 3L, 3L, 3L, 2L, 2L, 6L, 4L, 3L, 4L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 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, 3L, 4L, 2L, 6L, 6L, 4L, 4L, 4L, 6L, 3L, 4L, 6L, 3L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3L, 3L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 4L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 4L, 4L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 4L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 2L, 2L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 2L, 3L, 3L, 2L, 3L, 2L, 4L, 3L, 3L, 3L, 3L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 2L, 3L, 3L, 3L), .Label = c("", "CISCO", "MOTOROLA", "PACE"), class = "factor"), Receiver_TotalVideoDecoderErrors = c(3L, 204L, 0L, 0L, 3393L, 909L, 1556L, 48L, 0L, 0L, 0L, 182L, 19L, 0L, 0L, 0L, 77L, 0L, 0L, 0L, 6L, 1002L, 10L, 0L, 0L, 6938L, 0L, 299L, 49L, 245L, 0L, 41L, 0L, 0L, 717L, 31L, 0L, 75L, 37L, 71L, 0L, 40L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 1230L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 22L, 0L, 0L, 1384L, 95L, 0L, 0L, 0L, 437L, 119L, 910L, 0L, 0L, 8679L, 20L, 68L, 7L, 0L, 0L, 16L, 0L, 0L, 0L, 0L, 74L, 1L, 0L, 82L, 0L, 0L, 0L, 0L, 0L, 21L, 0L, 0L, 279L, 40L, 0L, 1483L, 3L, 0L, 132L, 0L, 0L, 171L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 90L, 0L, 0L, 0L, 0L, 0L, 111L, 0L, 0L, 0L, 0L, 0L, 18L, 0L, 0L, 0L, 217L, 0L, 0L, 1687L, 0L, 0L, 25L, 0L, 0L, 0L, 0L, 0L, 60L, 0L, 0L, 7L, 0L, 0L, 0L, 0L, 1L, 20L, 0L, 0L, 0L, 0L, 0L, 230L, 0L, 169L, 0L, 0L, 0L, 889L, 0L, 3L, 0L, 48L, 2951L, 10L, 531L, 0L, 0L, 0L, 0L, 0L, 232L, 0L, 0L, 125L, 0L, 39L, 0L, 0L, 262L, 0L, 0L, 0L, 0L, 1270L, 6L, 0L, 0L, 88L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 297L, 124L, 419L, 0L, 483L, 280L, 0L, 0L, 127L, 93L, 368L, 0L, 209571L, 0L, 0L, 21L, 62L, 11L, 0L, 501L, 0L, 169L, 34L, 32L, 25L, 188L, 0L, 1596L, 0L, 41L, 183L, 0L, 805L, 3L, 0L, 0L, 0L, 0L, 297L, 90L, 0L, 0L, 0L, 0L, 691L, 0L, 0L, 4L, 0L, 0L, 0L, 0L, 0L, 23L, 52L, 0L, 0L, 0L, 0L, 58L, 18L, 93L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 9L, 0L, 0L, 11381L, 0L, 34L, 0L, 0L, 26L, 0L, 0L, 0L, 318L, 0L, 0L, 36L, 0L, 6534L, 22L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 18L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 35L, 0L, 0L, 30L, 0L, 0L, 0L, 51L, 0L, 7L, 0L, 84L, 0L, 9L, 0L, 0L, 48L, 65L, 23L, 0L, 60312L, 0L, 0L, 28L, 0L, 32L, 0L, 0L, 283L, 406L, 44L, 0L, 0L, 0L, 2L, 824L, 0L, 0L, 2487L, 95L, 0L, 0L, 0L, 0L, 0L, 56L, 0L, 1L, 4640L, 12L, 3626L, 0L, 0L, 0L, 420L, 0L, 0L, 0L, 49L, 0L, 78L, 8L, 0L, 0L, 0L, 380L, 0L, 0L, 7L, 1194L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 29L, 489L, 584L, 47L, 2L, 0L, 0L, 0L, 0L, 0L, 0L, 899L, 120L, 0L, 0L, 0L, 26L, 656L, 0L, 0L, 0L, 50L, 0L, 0L, 0L, 0L, 0L, 6L, 14L, 0L, 0L, 0L, 0L, 0L, 0L, 89L, 0L, 0L, 0L, 0L, 0L, 104L, 0L, 0L, 0L, 0L, 0L, 217L, 0L, 50L, 14L, 0L, 0L, 0L, 0L, 21L, 0L, 73L, 403L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 14L, 0L, 0L, 2769L, 5878L, 0L, 0L, 0L, 37L, 0L, 0L, 0L, 0L, 0L, 0L, 258L, 0L, 5560L, 0L, 0L, 722L, 0L, 0L, 707L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 95L, 0L, 0L, 13L, 0L, 37L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 150L, 65L, 0L, 0L, 0L, 78L, 0L, 0L, 0L, 4L, 10L, 25L, 0L, 0L, 0L, 0L, 0L, 13L, 0L, 0L, 0L, 0L, 0L, 47L, 103L, 0L, 9L, 0L, 116L, 27L, 0L, 7L, 0L, 0L, 6L, 3L, 831L, 1396L, 545L, 0L, 226L, 79L, 0L, 0L, 101L, 0L, 3370L, 0L, 36L, 98L, 25L, 0L, 290L, 0L, 3L, 0L, 193L, 0L, 0L, 10L, 0L, 0L, 0L, 188L, 4L, 0L, 3L, 0L, 0L, 0L, 155L, 0L, 0L, 0L, 0L, 0L, 58L, 0L, 0L, 56L, 0L, 0L, 209L, 60L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 458L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 40L, 0L, 0L, 4L, 1L, 0L, 0L, 5L, 0L, 548L, 123L, 387L, 723L, 0L, 522L, 384L, 0L, 0L, 0L, 0L, 472L, 1L, 0L, 0L, 0L, 24L, 0L, 91L, 0L, 0L, 11L, 47L, 0L, 11L, 0L, 0L, 27L, 17L, 156L, 0L, 29L, 5L, 0L, 0L, 0L, 15L, 79L, 0L, 0L, 0L, 137L, 0L, 75L, 0L, 0L, 0L, 0L, 0L, 0L, 670L, 0L, 0L, 0L, 17L, 23L, 1L, 0L, 160L, 0L, 0L, 235L, 0L, 272L, 16L, 0L, 1803L, 0L, 4780L, 26L, 0L, 90L, 17L, 0L, 1518L, 151L, 1L, 768L, 151L, 42L, 0L, 9161L, 57L, 0L, 0L, 73L, 0L, 0L, 0L, 0L, 3086L, 0L, 0L, 0L, 1896L, 0L, 240L, 165L, 0L, 0L, 722L, 282L, 0L, 0L, 0L, 0L, 0L, 0L, 3L, 4L, 0L, 0L, 0L, 0L, 212L, 0L, 0L, 0L, 0L, 285L, 0L, 0L, 9L, 1349L, 1417L, 30792L, 2163L, 0L, 0L, 0L, 0L, 969L, 0L, 0L, 0L, 8L, 0L, 100L, 109L, 48L, 0L, 100L, 109L, 48L, 0L, 0L, 61L, 0L, 0L, 0L, 86L, 967L, 2679L, 86L, 967L, 2679L, 0L, 0L, 0L, 32L, 0L, 0L, 32L, 0L, 4L, 0L, 0L, 54L, 341L, 0L, 54L, 341L, 0L, 0L, 0L, 0L, 401L, 83L, 83L, 6L, 0L, 0L, 46L, 442L, 0L, 46L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 245L, 0L, 245L, 599L, 78L, 0L, 58L, 54L, 0L, 54L, 0L, 0L, 16L, 0L, 0L, 0L, 0L, 30L, 0L, 0L, 305L, 0L, 305L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 27L, 0L, 0L, 0L, 0L, 536L, 0L, 0L, 0L, 10L, 66L, 20L, 66L, 899L, 4L, 0L, 0L, 233L, 0L, 0L, 0L, 0L, 233L, 3L, 0L, 0L, 8L, 0L, 0L, 0L, 0L, 13L, 0L, 0L, 428L, 0L, 0L, 0L, 428L, 0L, 172L, 0L, 0L, 0L, 12L, 13L, 13L, 0L, 35L, 0L, 0L, 0L, 0L, 0L, 0L, 49L, 0L, 0L, 0L, 0L, 639L, 0L, 78L, 0L, 4386L, 78L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 2076L, 6L, 0L, 0L )), .Names = c("BoxType", "BoxVendor", "Receiver_TotalVideoDecoderErrors" ), class = "data.frame", row.names = c(NA, -999L))
The ifelse way Assuming your CSV has been loaded into a data frame called boxdata with the same column names as in the CSV: ifelse(boxdata$Receiver_TotalVideoDecoderErrors, 'Error', 'No error') Explanation The best way to demonstrate ifelse is by example: x <- 1:5 x_lessthan_4 <- x < 4 x_lessthan_4 # [1] TRUE TRUE TRUE FALSE FALSE if_lessthan_4 <- -x if_lessthan_4 # [1] -1 -2 -3 -4 -5 if_notlessthan_4 <- x + 100 if_notlessthan_4 # [1] 101 102 103 104 105 ifelse(test = if_notlessthan_4, yes = if_lessthan_4, no = if_notlessthan_4) # [1] -1 -2 -3 104 105 Hopefully it's clear what this function does. Obviously you don't need to always name the arguments as long as they're in the right order; I'm just doing it here so you can see exactly what's going on. However, you'll notice that the expression ifelse(boxdata$Receiver_TotalVideoDecoderErrors, 'Error', 'No error') does not conform to this standard. It works because two things happen "under the hood": test is "coerced" to logical, so if I pass in something like test = c(1, 3, 0) the value of test will be replaced with as.logical(test), so test = c(1, 3, 0) becomes test = c(TRUE, TRUE, FALSE). yes and no are "recycled" if they are shorter than test, and truncated if they are longer. Recycling is again best demonstrated by example: test <- c(TRUE, FALSE, TRUE, TRUE, FALSE) yes <- c(1, 2, 3) no <- c(99, 100, 101, 102, 103, 104) c(length(test), length(yes), length(no)) # [1] 5 3 6 ifelse(test, yes, no) # [1] 1 100 3 1 103 These things are documented, but they're easy to miss if you're not used to reading the R help files. And finally, the help file also says this, which is worth pointing out: Missing values in test give missing values in the result. This means that ifelse(c(NA, 1, 0, 1), 99, 100) returns c(NA, 99, 100, 99). So ifelse(boxdata$Receiver_TotalVideoDecoderErrors, 'Error', 'No error') is equivalent to test <- as.logical(boxdata$Receiver_TotalVideoDecoderErrors) yes <- rep('Error', length(test)) no <- rep('No error', length(test)) ifelse(test, yes, no) The slick way Or let argument recycling to do the work for you. Shorter and more efficient, but maybe less readable to someone who isn't familiar with R: c('No error', 'Error')[as.logical(boxdata$Receiver_TotalVideoDecoderErrors) + 1] or c('Error', 'No error')[!as.logical(boxdata$Receiver_TotalVideoDecoderErrors) + 1] Explanation First, the statement as.logical(boxdata$Receiver_TotalVideoDecoderErrors) + 1 is equivalent to: i <- as.logical(boxdata$Receiver_TotalVideoDecoderErrors) i <- as.numeric(i) # FALSE -> 0, TRUE -> 1 i <- i + rep(1, length(i)) Finally, recycling is applied to subsetting as well: c('No error', 'Error')[c(1, 2, 1, 1, 2)] # [1] "No error" "Error" "No error" "No error" "Error" So the entire thing is equivalent to: i <- as.logical(boxdata$Receiver_TotalVideoDecoderErrors) i <- as.numeric(i) i <- i + rep(1, length(i)) c('No error', 'Error')[i] The long way (suggested here) This way doesn't need much explanation. It's a lot more typing but it's easy to read and it's flexible: x <- boxdata$Receiver_TotalVideoDecoderErrors x[x > 0] <- 'Error' x[x == 0] <- 'No error'
Try using the which command and some logical operators to quickly determine the index locations for the values that are equal to 0 and those that are greater than 0. From there you can replace the original numeric values with a string. Try something like this: data$Receiver_TotalVideoDecoderErrors[which(data$Receiver_TotalVideoDecoderErrors == 0)] = "no error" data$Receiver_TotalVideoDecoderErrors[which(data$Receiver_TotalVideoDecoderErrors > 0)] = "error" Hope that helps.
Incorrect frequency using ggplot2 histogram
This is something I noticed just as I was about to put the histograms in my thesis. I noticed that the frequency did not reflect the correct count as displayed in the graph. To double check I tried this in excel and it was proved that the frequency being displayed in R using the ggplot2 was indeed incorrect. I noticed that in my syntax I had applied the xlim function. I removed that out of curiosity to see the result and then magically ggplot2 produced the correct histogram! This is the code that I'm using: ggplot(data, aes(x = variable) )+ geom_histogram(binwidth = 1) + xlim(0, 40) The one that is producing the correct histogram graph is this: hist(data$variable, breaks = seq(0, 40, 1), ylim = c(0,700)) Can anybody please help me here? I've spent a lot of time trying to get this to work but to no avail. Any help would be greatly appreciated. # example data variable <- c(1L, 1L, 1L, 3L, 4L, 1L, 2L, 1L, 2L, 0L, 1L, 2L, 1L, 1L, 0L, 3L, 1L, 2L, 2L, 3L, 2L, 3L, 2L, 2L, 1L, 0L, 5L, 0L, 0L, 2L, 1L, 1L, 2L, 1L, 3L, 2L, 5L, 4L, 3L, 2L, 3L, 0L, 1L, 1L, 1L, 1L, 2L, 0L, 2L, 1L, 3L, 1L, 4L, 2L, 6L, 2L, 1L, 6L, 5L, 5L, 1L, 1L, 0L, 2L, 1L, 1L, 0L, 0L, 1L, 2L, 1L, 1L, 5L, 2L, 1L, 0L, 3L, 2L, 2L, 4L, 6L, 3L, 2L, 1L, 6L, 1L, 4L, 2L, 1L, 2L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 2L, 3L, 1L, 3L, 2L, 2L, 1L, 1L, 2L, 13L, 3L, 2L, 5L, 5L, 1L, 3L, 0L, 2L, 1L, 2L, 1L, 0L, 10L, 2L, 0L, 1L, 2L, 2L, 0L, 1L, 4L, 0L, 2L, 0L, 0L, 1L, 0L, 1L, 13L, 15L, 2L, 4L, 4L, 12L, 7L, 4L, 4L, 0L, 0L, 1L, 0L, 1L, 2L, 6L, 3L, 0L, 2L, 2L, 0L, 1L, 5L, 0L, 3L, 3L, 4L, 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0L, 1L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 2L, 0L, 0L, 1L, 1L, 0L, 2L, 1L, 0L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 5L, 2L, 2L, 1L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 2L, 0L, 0L, 1L, 1L, 0L, 1L, 2L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 2L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 2L, 1L, 2L, 1L, 0L, 1L, 0L, 2L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 0L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 2L, 1L, 0L, 0L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 11L, 1L, 0L, 0L, 1L, 1L, 3L, 4L, 0L, 0L, 0L, 1L, 6L) data <- data.frame(variable)
Ok I see, the difference is the specific definition of a bin, i.e. whether you use [0,1) or [0,1] for the first bin. Try ggplot(data, aes(x = variable)) + geom_histogram(breaks = seq(0,40,by = 1), right = TRUE) or if you don't use explicit breaks, you have to specify origin additionaly, either by xlim as you did, or ggplot(data, aes(x = variable)) + geom_histogram(binwidth = 1, right = TRUE, origin = 0)