Skip to content

Commit

Permalink
ready for CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasH2 committed Feb 8, 2024
1 parent b67f904 commit a288bc0
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 16 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() +
Expand All @@ -47,17 +48,22 @@ plt +
stat_brace() +
stat_bracetext()
```
<img src="readme_files/braces_with_text.png"/>

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")
```
<img src="readme_files/custom_text.png"/>

## Rotation

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)
Expand All @@ -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)
```
<img src="readme_files/inside.png"/>

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
Expand Down
Binary file added readme_files/braces_with_text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_files/custom_distance.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_files/custom_rotation.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_files/custom_text.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified readme_files/default_braces.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added readme_files/inside.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 24 additions & 9 deletions vignettes/introduction_to_ggbrace.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
```


Expand All @@ -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
Expand Down

0 comments on commit a288bc0

Please sign in to comment.