如何在混合字符串中仅制作较低的案例字符斜体
这个问题是通过试图解决这个问题如何使用ggplot2在斜体上写下x标签的部分字符串?:
我想知道我们如何只能在字符串中斜体字符降低情况:
string <- "wbfV/wcvB"
[1] "wbfV/wcvB"
所需的输出:
- wbf v/ wcv b
背景: 我想将其用于图中标记。
我想这样做是这样做的,但是显然它不起作用:
library(stringr)
expression(str_detect(string, '[a-z]'~italic(str_detect(string, '[A-Z]'))))
我试图标记
plot(1, xlab=expression(str_detect(string, '[a-z]'~italic(str_detect(string, '[A-Z]')))))
This question raised by trying to solve this one How to write partial string of X labels in italics using ggplot2?:
I want to know how we could only italicize characters in a string that are lower case:
string <- "wbfV/wcvB"
[1] "wbfV/wcvB"
Desired output:
- wbfV/wcvB
Background:
I would like to use it then for labelling in a plot.
I thought to do it like this way, but obviously it is not working:
library(stringr)
expression(str_detect(string, '[a-z]'~italic(str_detect(string, '[A-Z]'))))
which I tried to label
plot(1, xlab=expression(str_detect(string, '[a-z]'~italic(str_detect(string, '[A-Z]')))))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我并不真正熟悉直接在R中使用表达式,我只使用过
lastx2exp
,所以我也在这里使用它。此任务的关键是对Lookarounds进行正确的分开。然后,您可以轻松地制作其他所有底带斜体。在2022-07-30创建的 preprex软件包(v2.0.1)
the Regex由两个部分组成,每个部分都有两个lougharounds:
I'm not really familiar with using expressions in R directly, I have only ever used
latex2exp
, so I'll be using it here as well. The key to this task is doing the right split with lookarounds. Then you can easily make every other substring italic.Created on 2022-07-30 by the reprex package (v2.0.1)
The regex consists of two parts with two lookarounds each: