ggplot2 subscript in x-axis labels(ticks, legend)

#==============================
# ggplot2: subscript in x-axis labels(ticks)
rm(list=ls(all=TRUE))
library(ggplot2)
data <- data.frame(names=tolower(LETTERS[1:4]),mean_p=runif(4))

p <- ggplot(data,aes(x=names,y=mean_p))
p <- p + geom_bar(colour="black",fill="white")
p <- p + xlab("expressions") + scale_y_continuous(expression(paste("Wacky Data")))
p <- p + scale_x_discrete(labels=c(a=expression(paste(Delta^2)),
                               b=expression(paste(q^n)),
                               c=expression(log(z)),
                               d=expression(paste(omega / (x + 13)^2))))

p

# from: http://stackoverflow.com/questions/6202667/how-to-use-subscripts-in-ggplot2-legends-r

#==============================
# ggplot2: subscript in y-axis labels
rm(list=ls(all=TRUE))
library(ggplot2)
dat <- data.frame(x = rnorm(100), y = rnorm(100))
ggplot(dat, aes(x=x,y=y)) +
     geom_point() +
     labs(y=expression(Blah[1*d]))

ggplot(dat, aes(x=x,y=y)) +
     geom_point() +
     labs(y=expression(Blah["1d"]))
    
ggplot(dat, aes(x=x,y=y)) +
    geom_point() +
    labs(y=expression(Blah[1*d]*"%"))    
    
# from: http://stackoverflow.com/questions/17334759/subscript-letters-in-ggplot-axis-label
# http://stackoverflow.com/questions/8514478/subscripts-in-xlabels-in-ggplot2
# http://stackoverflow.com/questions/15125628/putting-mathematical-symbols-and-subscripts-mixed-with-regular-letters-in-r-ggpl
# http://www.janeshdevkota.com/blog/using-superscripts-and-subscripts-in-ggplot2/

时间: 2024-07-30 13:52:13

ggplot2 subscript in x-axis labels(ticks, legend)的相关文章

[Python] Statistical analysis of time series

Global Statistics: Common seen methods as such 1. Mean 2. Median 3. Standard deviation:  the larger the number means it various a lot. 4. Sum. Rolling Statistics: It use a time window, moving forward each day to calculate the mean value of those wind

Econ 3818 R data project

Econ 3818Spring 2019R data project Unlike your other R assignments, this assignment is individual work only. You may discuss your project with classmates but you must have your own unique project.. Final write-up is due via email by 5 pm on Monday, A

ggplot2包--R可视化

1.ggplot2发展历程 ggplot2是Hadley在爱荷华州立大学博士期间的作品,也是他博士论文的主题之一,实际上ggplot2还有个前身ggplot,但后来废弃了,某种程度上这也是Hadley写软件的特 征,熟悉他的人就知道这不是他第一个“2”版本的包了(还有reshape2).带2的包和原来的包在语法上会有很大的改动,基本上不兼容.尽管如此,他的R代码风格在R社区可谓独树一帜,尤其是他的代码结构很好,可读性很高,ggplot2是R代码抽象的一个杰作.读者若感兴趣,可以在GitHub网站

R:ggplot2数据可视化——进阶(3)

Part 3: Top 50 ggplot2 Visualizations - The Master List, 结合进阶1.2内容构建图形 有效的图形是: 不扭曲事实 传递正确的信息 简洁优雅 美观是为了凸显信息 而不要盖过信息 不超载信息 1 相关性图 散点图 最常用 # install.packages("ggplot2") # load package and data options(scipen=999) # turn-off scientific notation lik

ggplot2作图详解7(完):主题(theme)设置

凡是和数据无关的图形设置内容理论上都可以归为主题类,但考虑到一些内容(如坐标轴)的特殊性,可以允许例外的情况.主题的设置相当繁琐,很容易就占用了 大量的作图时间,应尽量把这些东西简化,把注意力主要放在数据分析上.基于这种考虑,ggplot2主题设置的内容虽然相当多,本文仅在总体上作一简单介 绍. 1 theme函数及其参数 让使用者在数据分析阶段能专注于数据而不是图形细节,这是数据可视化分析工具是否合格的标准之一.某些作图软件(或自以为有作图能力的软件)给出的初始图 形简直惨不忍睹,不花时间修改

TeeChart中Axis的CalcIncrement属性

private void Init() { tChart = new TChart(); panel1.Controls.Add(tChart); tChart.Aspect.View3D = false; tChart.Dock = DockStyle.Fill; Line line = new Line(); tChart.Series.Add(line); //double[] array = {13.676251, 13.676252, 13.676254, 13.676251, 13.

matplotlib之legend

在<matplotlib极坐标系应用之雷达图> 中,我们提出了这个问题"图例中每种成员的颜色是怎样和极坐标相应的成员的颜色相对应的呢",那么接下来我们说说legend的一般使用和设置. 调用legend()一般有三种方式: 方式1. 自动检测,直接调用legend(); 在plot()时就指定图例labels,再直接调用legend()就好了,或者在plot中指定plot elements,然后通过set_label函数指定图例labels 1 plt.plot([1, 2

《R in Nutshell》 读书笔记(连载)

R in Nutshell 前言 例子(nutshell包) 本书中的例子包括在nutshell的R包中,使用数据,需加载nutshell包 install.packages("nutshell") 第一部分:基础 第一章 批处理(Batch Mode) R provides a way to run a large set of commands in sequence and save the results to a file. 以batch mode运行R的一种方式是:使用系统

R语言颜色综合运用与色彩方案共享

R语言颜色综合运用与色彩方案共享 小魔方 EasyCharts 2016-11-21 今天这篇主要讲解R语言颜色综合运用,主要跟大家介绍如何提取那些专业色彩包中的颜色搭配用于在基础绘图系统和高级绘图系统中共享. 其实无论是R语言的预设配色系统.自定义颜色表还是哪些专属配色包,我们所使用(或者R语言识别的)的仅仅就是一组字符向量所代表的色值而已,并不神秘. 通过scales中的色彩获取函数,我们可以将专属配色主题(RColorBrewer.ggthemes)中的配色主题提取出来,以函数的形式传递给