diff --git a/README.md b/README.md index 89e92f5..e1d140b 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,12 @@ devtools::install_github("nicolash2/ggbrace") # Plotting braces The new version of ggbrace uses only `stat_brace` to automatically enclose data points. `stat_bracetext` is used to generate fitting text. -In our example we use the mtcars data to create a dotplot. Then we look at how each of the three different modes draws braces to that plot. +In our example we use the iris data to create a dotplot. Then we look at how each of the three different modes draws braces to that plot. ``` r library(ggplot2) library(ggbrace) +data(iris) plt <- ggplot(iris, aes(x=Sepal.Length, y=Sepal.Width, color=Species, label=Species)) + geom_point() + @@ -47,6 +48,15 @@ plt + stat_brace() + stat_bracetext() ``` + + +We can modify the text in the same way we would modify other text in ggplot. We can also switch between different text geoms (e.g. `geom=label`). + +``` r +plt + + stat_brace() + + stat_bracetext(size=6, angle=15, fontface="bold") +``` ## Rotation @@ -54,10 +64,6 @@ plt + We can rotate the braces by 90, 180 or 270 degrees via the `rotate` argument. Note that any changes in `stat_brace` also have to be made in `stat_bracetext` so that the text appears at the right position ``` r -plt + - stat_brace(rotate = 90) + - stat_bracetext() - plt + stat_brace(rotate = 90) + stat_bracetext(rotate = 90) @@ -67,14 +73,14 @@ plt + ## Location -For `stat_brace`, the location of the brace is beside the data points by default. We can change that by setting the paramter `outside` to `FALSE`. +By default, the location of the brace is beside the data points by default. We can change that by setting the paramter `outside` to `FALSE`. ```r plt + stat_brace(outside = FALSE) ``` -When using the default We can define how far away, where and how big the braces are. We can also define the `bending`, i.e. the curvature. +By default, braces have a position and shape that is calculated based on their data points.The position can be changed with the parameters `distance` (to the data points) and `outerstart` (in the coordinate system). The width of the braces can be set with the `width` argument (absolute coordinate system units), while the bending of the brace can be set with `bending` (number from 0 to 1). ```r plt + stat_brace(distance = 2) # the braces are put at a defined distance to the last data point of their group diff --git a/readme_files/braces_with_text.png b/readme_files/braces_with_text.png new file mode 100644 index 0000000..98d38b4 Binary files /dev/null and b/readme_files/braces_with_text.png differ diff --git a/readme_files/custom_distance.png b/readme_files/custom_distance.png index 2d92ccf..2bb7d0c 100644 Binary files a/readme_files/custom_distance.png and b/readme_files/custom_distance.png differ diff --git a/readme_files/custom_rotation.png b/readme_files/custom_rotation.png index 156e76c..8b25eaf 100644 Binary files a/readme_files/custom_rotation.png and b/readme_files/custom_rotation.png differ diff --git a/readme_files/custom_text.png b/readme_files/custom_text.png index 89bd150..7accc99 100644 Binary files a/readme_files/custom_text.png and b/readme_files/custom_text.png differ diff --git a/readme_files/default_braces.png b/readme_files/default_braces.png index 40eab7e..7fec058 100644 Binary files a/readme_files/default_braces.png and b/readme_files/default_braces.png differ diff --git a/readme_files/inside.png b/readme_files/inside.png new file mode 100644 index 0000000..1a431c4 Binary files /dev/null and b/readme_files/inside.png differ diff --git a/vignettes/introduction_to_ggbrace.Rmd b/vignettes/introduction_to_ggbrace.Rmd index 4bdbfb9..651b536 100644 --- a/vignettes/introduction_to_ggbrace.Rmd +++ b/vignettes/introduction_to_ggbrace.Rmd @@ -46,12 +46,16 @@ plt + ## Labels -We can add labels to the braces. For that the `labelsize` parameter has to be set. The label for single braces with `geom_brace` must be defined as a string, whereas `stat_brace` and `geom_brace` with `inherit.aes=T` accept it in the mapping (we defined `label=Species` in the main plot already). As the third plot shows, we can also define the space between the brace pointer and the label. +We can modify the text in the same way we would modify other text in ggplot. We can also switch between different text geoms (e.g. `geom=label`). ```{r} plt + stat_brace()+ - stat_bracetext(size=6) + stat_bracetext(size=6, angle=15, fontface="bold") + +plt + + stat_brace()+ + stat_bracetext(geom="label") ``` ## Rotation @@ -60,8 +64,8 @@ We can rotate the braces by 90, 180 or 270 degrees via the `rotate` arguement. T ```{r} plt + - stat_brace(rotate=0)+ - stat_bracetext(rotate=0, textdistance=0, angle=30) + stat_brace(rotate=90)+ + stat_bracetext(rotate=90) ``` @@ -71,25 +75,36 @@ plt + stat_brace(rotate = 90) ## Location -For `stat_brace`, the location of the brace is beside the data points. We can define how far away, where and how big the braces are. We can also define the `bending`, i.e. the curvature. This last parameter can also be set in `geom_brace` (not shown here). +By default, the location of the brace is beside the data points. We can define how far away, where and how big the braces are. We can also define the `bending`, i.e. the curvature. This last parameter can also be set in `geom_brace` (not shown here). + +```{r} +plt + stat_brace(outside = FALSE) # the braces are put at a defined distance to the last data point of their group +``` + +By default, braces have a position and shape that is calculated based on their data points.The position can be changed with the parameters `distance` (to the data points) and `outerstart` (in the coordinate system). The width of the braces can be set with the `width` argument (absolute coordinate system units), while the bending of the brace can be set with `bending` (number from 0 to 1). + +- all braces are put at the same distance to their data points ```{r} -plt + stat_brace(distance = 2) # the braces are put at a defined distance to the last data point of their group +plt + stat_brace(distance = 2) ``` +- all braces are put at the same position ```{r} -plt + stat_brace(outerstart = 5) # all braces are put at the same position +plt + stat_brace(outerstart = 5) ``` +- all braces get the same width ```{r} -plt + stat_brace(outerstart = 5, width = 1) # all braces get the same width +plt + stat_brace(outerstart = 5, width = 1) ``` +- all braces get the same curvature ```{r} -plt + stat_brace(outerstart = 5, width = 1, bending = 0.1) # all braces get the same curvature +plt + stat_brace(outerstart = 5, width = 1, bending = 0.1) ``` # Outside of plotting area