Coder Social home page Coder Social logo

directlabels's Introduction

./logos/directlabels logo (orange).png

Build Status (Travis) Code Coverage (Codecov)


Installation from CRAN

install.packages("directlabels")

Install development version from GitHub

Development of directlabels on R-Forge stopped on 16 June 2015. Please install the development version from GitHub instead:

if(!require(devtools))install.packages("devtools")
devtools::install_github("tdhock/directlabels")

Changes are listed in NEWS.

Usage examples

Please check the documentation page (with links to examples for specific methods) and the page with several advanced examples.

Development and documentation

Documentation in R/*.R files is used to make man/*.Rd files using inlinedocs:

devtools::install_github("tdhock/inlinedocs")
inlinedocs::package.skeleton.dx("path/to/directlabels")

The directlabels documentation examples site can be generated via the gh-pages branch by using:

directlabels::dldoc("path/to/directlabels")

Be careful about what you put in each of the R code files – they are used to generate the documentation. For example, R/dotplot.R defines just two R objects: angled.endpoints and top.qp. Don’t add anything to this file unless you want it to show up in the docs as another Positioning Method for dotplots. Miscellaneous functions that could be helpful for constructing Positioning Methods should be put in R/utility.function.R.

directlabels's People

Contributors

anirban166 avatar hadley avatar jonovik avatar pratishrai avatar tdhock avatar teunbrand avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

directlabels's Issues

overlapping labels for multiple levels when using `geom_dl` with `last.bumpup` method

Using directlabels_2015.12.16and ggplot2_2.1.0 , I think there is a slight issue with geom_dl when using the last.bumpup method with multiple levels on x. I also describe this on SO in section add-on 2:

set.seed(0)
x <- data.frame(label=LETTERS[1:24], 
                g1 = c("a"),
                g2 = c("a", "b"),
                y = rnorm(24))
x$g1 <- as.factor(x$g1)
x$g2 <- as.factor(x$g2)
x$xpos1 <- as.numeric(x$g1) + .25
x$xpos2 <- as.numeric(x$g2) + .25

The label placement for one level is fine.

ggplot(x, aes(x=g1, y=y)) + 
  geom_boxplot(width=.4) +
  geom_point(col="blue") +
  geom_dl(aes(x=xpos1, label=label), method= "last.bumpup")

For two levels some label overlaps remain.

ggplot(x, aes(x=g2, y=y)) + 
  geom_boxplot(width=.4) +
  geom_point(col="blue") +
  geom_dl(aes(x=xpos2, label=label), method= "last.bumpup")

Same for three levels...

unique dlgrob names?

if there is a ggplot with more than one geom_dl, and they get the same grob name "dlgrob" then only the first will be drawn. I was expecting both should be drawn regardless of name.
Putting browser inside of drawDetails.dlgrob we see that it gets the same data (from the first geom) in both cases.
TODO create MRE.
is this an issue with grid or ggplot2?

Labels for LARS plot

I am analyzing my data using Least Angle Regression (LAR) methods using the "lars" package. I would like to create a quality plot using ggplot2 and then put labels for each line using "directlablels" package.
I can create the LARS plot using ggplot2, but when I use the functions of directlablels package (such as direct.label (p,"maxvar.points"), I get an error message (see below):

#error message---------------------------------------------------
"Error in parse(text = elt) : :2:0: unexpected end of input 1: ~ ^"
In addition: Warning message:
Using as.character() on a quosure is deprecated as of rlang 0.3.0.
Please use as_label() or as_name() instead.
#---------------------------------------------------------------------------------
#Here are my codes

09/02/2021

Lars plot using ggplot2

library(ggplot2); library(lars);library(devtools); library(reshape2); library(ElemStatLearn);
library(directlabels); library(quadprog)

##################################################

Lars plot using AMR data

========================================

A) Creating LARS plot using lars package

#========================================
rm(list=ls())

setwd("D:/Data_2")
dat <- read.csv("AMR_DDDRate_V2.csv", sep=",", header=TRUE, na.string=NA)
names(dat)

delete rows with zero data for HA_MRSA variable

dat1 <- dat[-c(3, 7, 9,10,17,19,22),]
dat1$HA_MRSA

In this model, we tested the model after removing the zero data for HA_MRSA variable

m0 <-lars(x=as.matrix(dat1[,-c(1:5)]),y=dat1[,3],type="lar",normalize=TRUE)

x11()
plot(m0);# suggests 3 steps
title("HA_MRSA >0", adj = 0, line = 2.5, col="blue")
print(m0)

#=========================================

B) creating LARS plot using ggplot2

#========================================
names(dat)

ycol <- which(names(dat)=="HA_MRSA")
x <- as.matrix(dat[-ycol])
y <- dat[[ycol]]

library(lars)
fit <-lars(x=as.matrix(dat1[,-c(1:5)]),y=dat1[,3],type="lar",normalize=TRUE) # type="lasso"
beta <- scale(coef(fit),FALSE,1/fit$normx)
arclength <- rowSums(abs(beta))/max(rowSums(abs(beta))) # LARS

library(reshape2)
path <- data.frame(melt(beta),arclength)
names(path)[1:3] <- c("step","variable","standardized.coef")

library(ggplot2)
p1 <- ggplot(path,aes(arclength,standardized.coef,colour=variable))+
geom_line(aes(group=variable))+
ggtitle("LASSO path for HA_MRSA data calculated using the LARS")+
theme(legend.position = "none") +
xlab("Sum of beta/max of sum of beta")+
ylab("standardised coefficinets") +
xlim(0,1)

x11(); p1

direct.label(p,"angled.boxes")

direct.label(p1,"angled.boxes") # this creates the error message (see below)

Error Message #----------------------------------------------------------

#Error in parse(text = elt) : :2:0: unexpected end of input 1: ~ ^

#In addition: Warning message:
#Using as.character() on a quosure is deprecated as of rlang 0.3.0.
#Please use as_label() or as_name() instead.
#----------------------------------------------------------------------------------
AMR_DDDRate_V2.xlsx

Lars plot using ggplot2_Toby_2021_R Codes.pdf

Note: I will be ok with any other label options in your package.

#END
#############################################################################################

Direct label on smoothed line methods not working?

Hi, I am trying to use the method as per this stackoverflow answer here

This code...

library("ggplot2")
#install.packages("directlabels")
library(directlabels)
set.seed(124234345)

# Generate data
df.2 <- data.frame("n_gram" = c("word1"),
                   "year" = rep(100:199),
                   "match_count" = runif(100 ,min = 1000 , max = 2000))

df.2 <- rbind(df.2, data.frame("n_gram" = c("word2"),
                               "year" = rep(100:199),
                               "match_count" = runif(100 ,min = 1000 , max = 2000)) )

# use stat smooth with geom_dl to get matching direct labels.
span <- 0.3
ggplot(df.2, aes(year, match_count, group=n_gram, color=n_gram)) +
  geom_line(alpha = I(7/10), color="grey") +
  stat_smooth(size=2, span=span, se=F) +
  geom_dl(aes(label=n_gram), method = "last.qp", stat="smooth", span=span) +
  xlim(c(100,220))+
  guides(colour="none")

produces this error:

Warning message:
Computation failed in `stat_smooth()`:
object 'last.qp' of mode 'function' was not found 

Interestingly, as a side issue, I went to run the code in the documentation from geom_dl() and i got fatal errors from Rstudio, when printing some objects, as noted in the code. I tested on Rstudio cloud, and that code worked fine there, but I'm running a pretty standard and neat setup - happy to give more details if this can't be reproduced.

#from geom_dl help
  vad <- as.data.frame.table(VADeaths)
  names(vad) <- c("age","demographic","deaths")
  ## color + legend
  leg <- ggplot(vad,aes(deaths,age,colour=demographic))+
    geom_line(aes(group=demographic))+
    xlim(8,80)
  print(direct.label(leg,list("last.points",rot=30)))
  ## this is what direct.label is doing internally:
  labeled <- leg+
    geom_dl(aes(label=demographic), method=list("last.points",rot=30))+
    scale_colour_discrete(guide="none")
  print(labeled)
  ## no color, just direct labels!
  p <- ggplot(vad,aes(deaths,age))+
    geom_line(aes(group=demographic))+
    geom_dl(aes(label=demographic),method="top.qp") #error when printing !!!!!!!!!!
  print(p)
  ## add color:
  p+aes(colour=demographic)+
    scale_colour_discrete(guide="none")
  ## add linetype:
  p+aes(linetype=demographic)+
    scale_linetype(guide="none")
  ## no color, just direct labels
  library(nlme)
  bwbase <- ggplot(BodyWeight,aes(Time,weight,label=Rat))+
    geom_line(aes(group=Rat))+
    facet_grid(.~Diet)
  bw <- bwbase+geom_dl(method="last.qp") #error when printing !!!!!!!!!!
  print(bw)
  ## add some more direct labels
  bw2 <- bw+geom_dl(method="first.qp")
  print(bw2)
  ## add color
  colored <- bw2+aes(colour=Rat)+
    scale_colour_discrete(guide="none")
  print(colored)
  ## or just use direct.label if you use color:
  direct.label(bwbase+aes(colour=Rat),dl.combine("first.qp","last.qp"))
  
  ## iris data example
  giris <- ggplot(iris,aes(Petal.Length,Sepal.Length))+
    geom_point(aes(shape=Species))
  giris.labeled <- giris+
    geom_dl(aes(label=Species),method="smart.grid")+
    scale_shape_manual(values=c(setosa=1,virginica=6,versicolor=3),
                       guide="none")
  ##png("~/R/directlabels/www/scatter-bw-ggplot2.png",h=503,w=503)
  print(giris.labeled)
  ##dev.off()

Interpolation issues when plotting directlabels - Error in approx(x, y) : need at least two non-NA values to interpolate

Hallo Github,

using the following replicable code, I ran into an interpolation issue when plotting directlabels;

#*************************************************************************************
library(tidyverse); library(directlabels); library(ggplot2);

#Generating some theoretical data
xgrid <-seq(0, 1, 0.05)
ygrid <- seq(0, 1, 0.05)
data.fit <- expand.grid(PA=xgrid,UA=ygrid)
zmatrix <- 2*((data.fit$PA*data.fit$UA)/(data.fit$PA+data.fit$UA))
zmatrix[1]<-0
zmatrix <- matrix(zmatrix, nrow=21, ncol = 21)

p<-as.data.frame(zmatrix) %>% #convert the matrix to data frame
rownames_to_column() %>% #get row coordinates
gather(key, value, -rowname) %>% #convert to long format
mutate(key = as.numeric(gsub("V", "", key)), #convert the column names to numbers
rowname = as.numeric(rowname)) #%>%
data.fit <- dplyr::bind_cols(data.fit,p)

#plotting a direct labels

a <- ggplot() +
geom_contour(data=data.fit,aes(x = UA, y = PA, z = value, colour = ..level..), linetype = "dotdash")+
geom_abline(slope = -1, intercept = 1, colour = "blue")+
theme_classic()+
labs(x = "UA", y = "PA")

a <-direct.label(a, list("far.from.others.borders", "calc.boxes", "enlarge.box",
box.color = NA, fill = "transparent", "draw.rects"))
a

#*************************************************************************************
A figure with similar "contours" as the following is expected;

image

However, I got the following error;

#*************************************************************************************
Error in approx(x, y) : need at least two non-NA values to interpolate
In addition: Warning messages:
1: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
2: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
3: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
4: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
5: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
6: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
7: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
8: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
#*************************************************************************************
I am currently running on the following specifications;

#*************************************************************************************

sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] directlabels_2020.6.17 forcats_0.5.0 stringr_1.4.0 dplyr_1.0.1
[5] purrr_0.3.4 readr_1.3.1 tidyr_1.1.1 tibble_3.0.3
[9] ggplot2_3.3.2 tidyverse_1.3.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.5 cellranger_1.1.0 pillar_1.4.6 compiler_3.6.3 dbplyr_1.4.4
[6] tools_3.6.3 digest_0.6.25 jsonlite_1.7.0 lubridate_1.7.9 lifecycle_0.2.0
[11] gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.7 reprex_0.3.0 cli_2.0.2
[16] DBI_1.1.0 rstudioapi_0.11 haven_2.3.1 withr_2.2.0 xml2_1.3.2
[21] httr_1.4.2 fs_1.5.0 generics_0.0.2 vctrs_0.3.2 hms_0.5.3
[26] isoband_0.2.2 grid_3.6.3 tidyselect_1.1.0 glue_1.4.1 R6_2.4.1
[31] fansi_0.4.1 readxl_1.3.1 farver_2.0.3 modelr_0.1.8 blob_1.2.1
[36] magrittr_1.5 backports_1.1.7 scales_1.1.1 ellipsis_0.3.1 rvest_0.3.6
[41] assertthat_0.2.1 colorspace_1.4-1 labeling_0.3 quadprog_1.5-8 stringi_1.4.6
[46] munsell_0.5.0 broom_0.7.0 crayon_1.3.4

#*************************************************************************************
What is the cause of this error?

Error in serialize(object, connection = NULL, ascii = ascii) : object 'direction' not found

Used to work few months ago, updated to latest version but faced below error.

> library('directlabels')
> direct.label(ggplot(melted, aes(x=Sess, y=value/1000000, fill=variable, color=variable)) + geom_bar(stat='identity', colour='black', position='dodge') + xlab('Year') + ylab("HKD ('000,000)") + theme_wsj(base_family='Verdana') + scale_colour_wsj('colors6', '') + ggtitle("Annual Turnover and P&L HKD ('000,000)"), list(last.bumpup,hjust=0.45,cex=0.65))
- Error in serialize(object, connection = NULL, ascii = ascii) : 
-   object 'direction' not found

After update to 2024.1.21, specifying "method" arg to direct.label() leads to error

Thanks a lot for all of your work on this wonderful package, Toby!

The following example used to work as expected with a previous version of directlabels, but now fails:

library("directlabels")
library("ggplot2")

scatter <- qplot(jitter(hwy),jitter(cty),data=mpg,colour=class,
                 main="Fuel efficiency depends on car size")
print(direct.label(scatter))
print(direct.label(scatter, "last.bumpup"))

I now get the following error:

> print(direct.label(scatter, "last.bumpup"))
Error in get(method[[1]]) : object 'last.bumpup' not found

I checked the NEWS file but didn't see anything that seemed relevant for why this code might be expected to fail in the new version.

lattice issues

handling custom densityplot params in lattice?

problems with plotting color labels in lattice when col= is specified,
see etc/individual.R, and gabor.R

see etc/xYplot.R for a problem with plotting some weird trellis
objects.

Allow non-syntactic variable names.

direct.label() with a ggplot breaks if a variable name contains spaces.
Such names are often useful for automatic human-friendly labeling in plots.
Small reproducible example:

library(ggplot2)
library(directlabels)
mpg2 <- within(mpg, `car class` <- class)
# This works fine:
direct.label(ggplot(mpg, aes(hwy, cty, colour=class)) + geom_point())
# This fails:
direct.label(ggplot(mpg2, aes(hwy, cty, colour=`car class`)) + geom_point())
## Error in parse(text = x) : <text>:1:5: unexpected symbol
## 1: car class
##         ^

working with devel version of ggplot2?

Unsurprisingly, directlabels seems to fail with the devel version of ggplot. I will dig into this myself if I get a chance, but ... ??

e.g.:

dd <- data.frame(x=1:10,y=1:10,f=factor(rep(1:2,each=5)))
library(ggplot2)
g0 <- ggplot(dd,aes(x,y,colour=f))+geom_point()
g0
direct.label(g0)
## Error in switch(geom, density = "top.bumptwice", line = { :  EXPR must be a length 1 vector

The proximal problem is that g0$layers[[1]]$geom no longer has a name element for identifying its type ...

Error when positioning angled.boxes etc.

I am trying to replicate the contour plots and using direct.labels to position labels as described in https://stackoverflow.com/questions/38154679/r-adding-legend-and-directlabels-to-ggplot2-contour-plot. However, the examples beginning with the one using "angled.boxes" result in errors such as
rror in approx(x, y) : need at least two non-NA values to interpolate
In addition: Warning messages:
1: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
2: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
3: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
4: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
5: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
6: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
7: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
8: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
9: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values
10: In regularize.values(x, y, ties, missing(ties)) :
collapsing to unique 'x' values

I am running R 3.6 under CentOS 7, the latest version available in an official repository.

ggrepel functionality?

Hi, thanks for making an awesome package! I use it a lot for charts at work.

Sometimes, though, I have several time series and the labels get clumped together.

I'm also a user of ggrepel (https://github.com/slowkow/ggrepel) and was wondering if there was an avenue for combining the ideas from ggrepel with directlabels?

Add piping functionality to work with ggplot/dplyr

The tidyverse functions (dplyr) work with piping where
x %>% f(y)
becomes
f(x, y)

This makes it easy to chain a series of commands to filter, mutate, etc the data before plotting. It would be great if directlabels also accepted piped inputs so that it could be the final step without having to surround the entire statement or save the plot as an object first. Currently this is the way to apply direct labels to a ggplot:
require(tidyverse)
require(directlabels)

p <- ggplot(diamonds, aes(x = depth, color = cut)) + geom_density()
direct.label(p, "top.bumptwice")

Here is how it would look with piping:

diamonds %>%
ggplot(aes(x = depth, color = cut)) + geom_density() %>%
direct.label("top.bumptwice")

Direct Labels removing fill legend but labeling colour

Hi! I'm making a plot with two climate fields, one displayed as a geom_tile with the fill aesthetic mapped to the variable and the other displayed with geom_contour mapped to colour. Direct Labels correctly puts labels near the contours and removing the unnecessary colour legend. The problem is that it's also removing the most necessary fill legend.

Maybe there's a way to override the default behaviour but I couldn't find it.

Thanks.

testing ideas

From Paul Murrell:

  • drawDetails does not work with grid.force.
  • calling drawDetails.dlgrob is probly a bad idea.
  • makeContent works with grid.force but would be a lot of work.
    Perhaps one (crude) way forward is to simply add debugging/logging code
    to your package. Because everything is being drawn on-the-fly, you
    might have to calculate locations and sizes of objects inline and
    on-the-fly as well and record them somewhere (all conditional on a
    debugging flag). You could then post-process the logged debugging
    output to perform your tests.

Grouping within geom is not detected

Compare scatter with scatter2. Both are rendered the same, but when colour = class is defined in geom_point() instead of ggplot(), it isn't detected, causing an error.

library(ggplot2)
library(directlabels)
scatter <- qplot(jitter(hwy),jitter(cty),data=mpg,colour=class,
                main="Fuel efficiency depends on car size")
print(direct.label(scatter))

scatter2 <-
  ggplot(aes(jitter(hwy), jitter(cty)), data = mpg) +
  geom_point(aes(colour = class))
print(direct.label(scatter2))
#> Error: Each variable must have a unique name.
#> Problem variables: 'colour'

Thanks for the very cool package, though.

Work when package is not attached

This may be a proto issue

plot <- ggplot(mpg, aes(displ, hwy, colour = class)) +
  geom_point() +
  directlabels::geom_dl(aes(label = class), list("last.points",rot = 30))

plot # fails
library(proto)
plot # succeeds

Also ideally need to make proto just suggested, not imported (as in my PR)

directlabels and smoothing

It seems to me directlabels and geom_smooth in ggplot2 don't work well together. I have a theory that labels are placed based on unsmoothed data. I tried several placement functions. Here is an example with source here. Thanks!

dl.jitter

how does it work? it asks for numeric value but gives error

finer control of geom_dl/directlabel aesthetics?

I'm trying to draw a smooth plot with coloured ribbons (i.e. geom_smooth(..., aes(fill=g))) and direct-label with angled boxes, but I'm running into trouble.

  • direct.label() inherits the fill specification, so the boxes get filled in with the same colour as the text (uh-oh)
  • geom_dl doesn't seem to handle the application of the smooth stat properly

I spent a while hacking around with adding override.aes arguments to geom_dl, and/or ... arguments to direct.label, but so far without success ...

thanks!

reproducible example:

library(ggplot2); theme_set(theme_bw())
library(directlabels)
set.seed(101)
dd <- expand.grid(x=1:10,g=factor(1:2))
dd <- transform(dd,y =2+as.numeric(g)*x + rnorm(20,sd=4))
gg1 <- (ggplot(dd,aes(x,y,colour=g))
    + geom_smooth(alpha=0.1,formula=y~x,method="loess"))

## uncoloured ribbons: fine
direct.label(gg1,method="angled.boxes")

## coloured ribbons: 'fill' takes over the rectangle background
direct.label(gg1+aes(fill=g),method="angled.boxes")

## geom_dl() ignores the smooth stat ...
gg1 + geom_dl(method="angled.boxes", aes(label=g))

## this helps, but the positioning is still bad
gg1 + aes(fill=g) + geom_dl(method="angled.boxes", aes(label=g, x=x,y=y, colour=g), inherit.aes=FALSE)

special qp solver?

Implement a solver for vertical.qp, for portability (to remove dependency on quadprog).

Thumbnail image to be used in ggplot2 extensions gallery

I think plots made via positioning methods like last.qp, top.bumptwice and smart.grid would look good, as they are the best choices. The 350x300 versions (saved manually or via ggsave) get cramped up and some of the text labels gets cropped, so I'll go with a 700x600 version of the chosen plot. Here are the ones that I like:

chemscore

lars

projectionSeconds

4)ridge

sd

gcse

iris

sg

irise
The 350x300 version for this one fits well:
irise2

@tdhock Among these, which would you prefer to be shown? (or let me know if I should go for something else)

Also, for the short and long descriptions, are the ones from my coding plan okay? Here is what I had for those fields:
image

Let me know the modified sentences if you would prefer something else (for this contribution, it's better to have it in your words and with a picture you prefer since you are the author of the package!)

A helper function for this type of label?

Snipped from a larger plot:

image

The code that generates this is:

myplot + 
  annotate(geom = "text", x = mydata$x[320] + 30,
         y = mydata$fit[320] - 0.1,
         label = "IV only", hjust = 0, size = 4.5, color = "orange") +
  geom_segment(aes(x = mydata$x[320], 
                   y = mydata$fit[320],
                   xend = mydata$x[320],
                   yend = mydata$fit[320] - 0.1), color = "orange") +
  geom_segment(aes(x = mydata$x[320], 
                   y = mydata$fit[320] - 0.1,
                   xend = mydata$x[320] + 25,
                   yend = mydata$fit[320] - 0.1), color = "orange")

These could be nicely wrapped up into a function in directlabels.

Request: parse expressions for geom_dl()

Hi,

I was wondering if there is a way of parsing expressions to use as direct labels. For example, to use superscript, having test1^test2 as label would be plotted as test1test2. ggplot2 geom_text has a parse option that if set to TRUE will parse expressions.

For example, ggrepel has the parse flag to use expressions, but you have to "hide" the unwanted labels and leave only one per group to be able to do the same as with a directlabel. If I have to do this for different plots, with different groups, it is almost impossible to always select the point with the most optimal label placement.

See also this question in stackoverflow.

image labels

image labels: draw a grob on screen instead of assuming it is
text. Have a toggle for drawing images and/or text. Handle both in a
uniform way in Positioning Methods by just asking for the grob size
instead of the text size.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.