Re: [R] ggplot aestetics: beginner question - I am lost in endless possibilites

2016-12-15 Thread Hadley Wickham
You are going to find your life much easier if you:

* Organise your code so it's easier to read
* Use a consistent naming scheme for your variables
* Learn a bit more about how to modify variables succintly

Here's my rewriting of your script to make it easier to see what's going on.

library(tidyverse)

df <- tibble(
  name = c("Ernie","Ernie","Ernie", "Leon","Leon","Leon"),
  recorded_time = c("03.01.2011","04.01.2011","05.01.2011",
"04.01.2011","05.01.2011","06.01.2011"),
  known_state = c("breeding","moulting","moulting", "breeding","breeding",NA)
)
df$recorded_time <- lubridate::dmy(df$recorded_time)

ggplot(df) +
  geom_tile(
aes(recorded_time, name, fill = known_state),
colour = "black",
height = 0.5
  ) +
  scale_fill_discrete(na.value = "white")

Hadley

On Thu, Dec 15, 2016 at 8:22 PM, Dagmar  wrote:
> # Dear all,
> # I hope someone can help me with this. I am so lost and can't find a
> solution even though I spent hours on searching for a solution of that tiny
> problem.
> # Maybe someone of you could give me hint?
> #This is my string:
> exdatframe <- data.frame(Name=c("Ernie","Ernie","Ernie",
> "Leon","Leon","Leon"),
>   recordedTime=c("03.01.2011","04.01.2011","05.01.2011",
> "04.01.2011","05.01.2011","06.01.2011"),
>knownstate =c("breeding","moulting","moulting",
>  "breeding","breeding",NA))
> exdatframe
>
> exdatframeT <- as.POSIXct
> (strptime(as.character(exdatframe$recordedTime),"%d.%m.%Y"))
> exdatframeT
> exdatframe2 <- cbind(exdatframe, exdatframeT)
> exdatframe2$recordedTime <-NULL
> exdatframe2
> str(datframe)
>
> library(ggplot2)
> ggplot(exdatframe2)+geom_tile(aes(x=exdatframeT,y=Name,fill=knownstate),
> height=0.5)
>
> # Now all I want is:
> # 1) a black outline around the bars. Adding colour="black" like I have
> found elsewere on the internet doesn't work
> # 2) change the colours: E.g. I want white for NAs. I can't find a command
> to describe my wishes.
>
> #?
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
http://hadley.nz

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] ggplot aestetics: beginner question - I am lost in endless possibilites

2016-12-15 Thread John Kane via R-help
I cannot see how you get that code to run. It certainly does not on my machine 
and some of the manipulations don't make any sense as far as I can see.
I changed variable and data.frame names so I would not have to type so much and 
read in the data with the "stringsAsFactors = FALSE" option.
I then parsed the dates (called 'known' in my data.frame) using the package 
"lubridate"
dat1$mydate <- dmy(dat1$mydate)

My resulting data.frame called dat1 is presented in dput() format below.
Do I understand you correctly in that you want the NA values plotted as "white" 
and the outline on the tiles in black?
In any case as my first steps here is a revised program to just get the 
tileswith no effort to get the outline or change the colours of the fill.



 

On Thursday, December 15, 2016 4:24 AM, Dagmar  wrote:
 

 # Dear all,
# I hope someone can help me with this. I am so lost and can't find a 
solution even though I spent hours on searching for a solution of that 
tiny problem.
# Maybe someone of you could give me hint?
#This is my string:
exdatframe <- data.frame(Name=c("Ernie","Ernie","Ernie", 
"Leon","Leon","Leon"),
              recordedTime=c("03.01.2011","04.01.2011","05.01.2011",
"04.01.2011","05.01.2011","06.01.2011"),
                knownstate =c("breeding","moulting","moulting",
                              "breeding","breeding",NA))
exdatframe

exdatframeT <- as.POSIXct 
(strptime(as.character(exdatframe$recordedTime),"%d.%m.%Y"))
exdatframeT
exdatframe2 <- cbind(exdatframe, exdatframeT)
exdatframe2$recordedTime <-NULL
exdatframe2
str(datframe)

library(ggplot2)
ggplot(exdatframe2)+geom_tile(aes(x=exdatframeT,y=Name,fill=knownstate), 
height=0.5)

# Now all I want is:
# 1) a black outline around the bars. Adding colour="black" like I have 
found elsewere on the internet doesn't work
# 2) change the colours: E.g. I want white for NAs. I can't find a 
command to describe my wishes.

#?

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


   
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] ggplot aestetics: beginner question - I am lost in endless possibilites

2016-12-15 Thread Thierry Onkelinx
Here is a solution

ggplot(exdatframe2) +
  geom_tile(aes(x = exdatframeT, y = Name, fill = knownstate), colour =
"black", height = 0.5) +
  scale_fill_discrete(na.value = "white")

Best regards,

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2016-12-15 10:22 GMT+01:00 Dagmar :

> # Dear all,
> # I hope someone can help me with this. I am so lost and can't find a
> solution even though I spent hours on searching for a solution of that tiny
> problem.
> # Maybe someone of you could give me hint?
> #This is my string:
> exdatframe <- data.frame(Name=c("Ernie","Ernie","Ernie",
> "Leon","Leon","Leon"),
>   recordedTime=c("03.01.2011","04.01.2011","05.01.2011",
> "04.01.2011","05.01.2011","06.01.2011"),
>knownstate =c("breeding","moulting","moulting",
>  "breeding","breeding",NA))
> exdatframe
>
> exdatframeT <- as.POSIXct (strptime(as.character(exdatfr
> ame$recordedTime),"%d.%m.%Y"))
> exdatframeT
> exdatframe2 <- cbind(exdatframe, exdatframeT)
> exdatframe2$recordedTime <-NULL
> exdatframe2
> str(datframe)
>
> library(ggplot2)
> ggplot(exdatframe2)+geom_tile(aes(x=exdatframeT,y=Name,fill=knownstate),
> height=0.5)
>
> # Now all I want is:
> # 1) a black outline around the bars. Adding colour="black" like I have
> found elsewere on the internet doesn't work
> # 2) change the colours: E.g. I want white for NAs. I can't find a command
> to describe my wishes.
>
> #?
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posti
> ng-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] ggplot aestetics: beginner question - I am lost in endless possibilites

2016-12-15 Thread Dagmar

# Dear all,
# I hope someone can help me with this. I am so lost and can't find a 
solution even though I spent hours on searching for a solution of that 
tiny problem.

# Maybe someone of you could give me hint?
#This is my string:
exdatframe <- data.frame(Name=c("Ernie","Ernie","Ernie", 
"Leon","Leon","Leon"),

  recordedTime=c("03.01.2011","04.01.2011","05.01.2011",
"04.01.2011","05.01.2011","06.01.2011"),
   knownstate =c("breeding","moulting","moulting",
 "breeding","breeding",NA))
exdatframe

exdatframeT <- as.POSIXct 
(strptime(as.character(exdatframe$recordedTime),"%d.%m.%Y"))

exdatframeT
exdatframe2 <- cbind(exdatframe, exdatframeT)
exdatframe2$recordedTime <-NULL
exdatframe2
str(datframe)

library(ggplot2)
ggplot(exdatframe2)+geom_tile(aes(x=exdatframeT,y=Name,fill=knownstate), 
height=0.5)


# Now all I want is:
# 1) a black outline around the bars. Adding colour="black" like I have 
found elsewere on the internet doesn't work
# 2) change the colours: E.g. I want white for NAs. I can't find a 
command to describe my wishes.


#?

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.