r - 如何在ggplot中手动创建线型?
问题描述
我有以下数据框,我想绘制它:
df = data.frame(
a = 1:2,
b = 1:2)
p = ggplot(df, aes(a,b))
p + geom_line()
这很好,但我希望能够设置不同类型的线型,因为我有几个组。我访问这个网站: http: //www.sthda.com/english/wiki/ggplot2-line-types-how-to-change-line-types-of-a-graph-in-r-software#change-manually -外观线条。我试过了
p + geom_line(linetype = 'dashed')
然而,我想要一种完全按照我想要的方式构建生产线的方法(即,不是来自现成的模板)。例如,由长行和长空白组成的行。任何想法?
解决方案
您可以通过为 geom 函数提供十六进制字符串来指定您希望在线和离线的时间。从文档:
# An example with hex strings, the string "33" specifies three units on followed
# by three off and "3313" specifies three units on followed by three off followed
# by one on and finally three off.
f + geom_line(linetype = "3313")
推荐阅读
- c++ - 找出两个字符串输入是否是字谜,忽略空格、标点符号和数字
- php - 使用 Laravel Socialite 注册用户并重定向到表单以填写更多数据?
- sorting - 根据另一个表提供的某个列值对范围行进行排序
- sql - 使用以下 SQL Server TSQL 从 JSON 返回多行
- python - 在 python 中使用 shutil.copytree() 的问题
- java - 有没有办法在我的游戏中添加跳跃机制?
- c - 在堆栈上声明整数指针并在堆上分配值
- python - Alpha Vantage 使用 python 从损益表库中提取数据
- angular - 量角器测试中的正确用法是什么?等待期望(someFn()).toBe.. 或期望(await someFn()).toBe
- php - 在foreach php上更改对象的值