How to center LaTeX xtable output in full text width - position

I am using tufte-handout (http://mirrors.ibiblio.org/CTAN/macros/latex/contrib/tufte-latex/sample-handout.pdf) to create a small report in latex. I have a file code.Rnw that I knit into code.tex. Below is my code.Rnw:
\documentclass[12pt,english,nohyper]{tufte-handout}
\usepackage{longtable}
\usepackage{geometry}
\begin{document}
<<include=FALSE>>=
library(ggplot2)
library(xtable)
#
\centerline{\Large\bf This is my Main Title}
<<echo=FALSE,results='asis'>>=
fname='plot1.pdf'
pdf(fname,width=4,height=4)
print(qplot(mpg,cyl,data=mtcars))
{dev.off();invisible()}
cat(sprintf('\\begin{marginfigure}
\\includegraphics[width=0.98\\linewidth]{%s}
\\caption{\\label{mar:hist}MPG vs CYL in MTCARS dataset.}
\\end{marginfigure}',sub('\\.pdf','',fname)))
#
This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report.
This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report. This is the paragraph in my report.
\bigskip{}
<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:20,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))
print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
#
\end{document}
This produces the following output:
What I am trying to do is to allow the xtable output (Table 1) to be centered across the full text. By default, in the tufte-handout package, it seems to center the table in the left non-margin.
I have consulted several sources, including the one indicated in the first sentence of this current post. According to that reference, "Full page–width figures and tables may be placed in figure* or table* environments." I am unsure how to accomplish this, given that I am also knitting this report.

You can work around this problem by wrapping the longtable in a tufte fullwidth environment. This workaround also seems to require a small hack (in line 2) to fix the hsize, but it appears to work as intended.
\begin{fullwidth}
\makeatletter\setlength\hsize{\#tufte#fullwidth}\makeatother
<<echo=FALSE,results='asis'>>=
x.big <- xtable(mtcars[1:20,1:4], label ='tab:mtcars',caption ='This is the mtcar dataset head.',align = c("rr|lr|r"))
print(x.big, tabular.environment ='longtable', floating = FALSE, include.rownames=FALSE)
#
\end{fullwidth}

Related

How to add text on interactive Scatter on Altair?

I try to adapt the Selection Detail Example from altair doc (https://altair-viz.github.io/gallery/select_detail.html#selection-detail-example).
I won't detailed my Dataframe structure which is identical with the one from the example (included variable names).
The native code is working well :
# Data is prepared, now make a chart
selector = alt.selection_single(empty='all', fields=['id'])
base = alt.Chart(data).properties(
width=250,
height=250
).add_selection(selector)
points = base.mark_point(filled=True, size=200,opacity=0.9).encode(
x=alt.X('mean(y)',title='Durée de perception',scale=alt.Scale(domain=(11, 23))),
y=alt.Y('mean(x)',title='Taux de marge (%PM)'),
color=alt.condition(selector, 'id:O', alt.value('lightgray')),
tooltip = ['mean(y)','mean(x)']
)
timeseries = base.mark_bar(opacity=1).encode(
x=alt.X('time', title='Items'),
y=alt.Y('value', scale=alt.Scale(domain=(-1, 1)),stack=None),
color=alt.Color('id:O',scale=alt.Scale(domain=domain, range=range_))
#, legend=None)
).transform_filter(
selector
)
points | timeseries
No problem at this stage even if it could be useful to hide all the bars on right chart when no selection is made on the right chart (don't know if it's possible ?)
After that I try to add text to the scatter plot adding this at the end of the code :
text = points.mark_text(dy=-5).encode(
x=alt.X('mean(y)',title='Durée de perception',scale=alt.Scale(domain=(11, 23))),
y=alt.Y('mean(x)',title='NBV (%CA)'),
text='id:O'
)
(points + text) | timeseries
which leads to the following error message :
Javascript Error: Duplicate signal name: "selector094_tuple"
This usually means there's a typo in your chart specification. See the javascript console for the full traceback.
If you have any idea on how to do, i would be grateful
Thanks
The issue is that you cannot add the same selection to two different layers, which you do implicitly by deriving text from points. Try this instead:
text = alt.Chart(data).mark_text(dy=-5).encode(
x=alt.X('mean(y)',title='Durée de perception',scale=alt.Scale(domain=(11, 23))),
y=alt.Y('mean(x)',title='NBV (%CA)'),
text='id:O'
)
(points + text) | timeseries

Is there a way to show tooltips in ALL the sub charts of a faceted chart or concatenated charts, where sub charts are "joined" by selection?

Just like we can highlight point(s) in one of the charts of a concatenated chart or a faceted chart and the corresponding point(s) will also get highlighted in the other chart, I was wondering if the same can be done with a tooltip.
I have been able to come up with a demo using mark_text as you can see below. But the biggest challenge is not being able to show multiple encodings as text. Tooltips make that really easy by just mentioning all the encodings in a list. So I was thinking if there is a way to do that in Altair.
Or is this not the expected behavior of Tooltips, and they are ONLY supposed to highlight the point over which the mouse is hovering even if other charts may have a common selection?
Whatever I have tried with Tooltips only works in a single chart, the other point despite being highlighted does not also show a tooltip.
Code:
import altair as alt
from vega_datasets import data
source = data.cars()
highlight = alt.selection(type='single', on="mouseover", empty='none')
base = alt.Chart(source).encode(
y='Miles_per_Gallon',
color=alt.condition(highlight, 'Origin', alt.ColorValue('gray')),
)
mpg = base.mark_point().encode(
x='Horsepower',
size=alt.condition(highlight, alt.value(150), alt.value(50))).add_selection(
highlight
)
acc = base.mark_point().encode(
x='Acceleration',
size=alt.condition(highlight, alt.value(150), alt.value(50))).add_selection(
highlight
)
text_mpg = base.mark_text(dx=5, dy=-10, size=15).encode(
x='Horsepower',
y='Miles_per_Gallon',
text=alt.condition(highlight, 'Horsepower:Q', alt.value('')),
)
text_acc = base.mark_text(dx=5, dy=-10, size=15).encode(
x='Acceleration',
y='Miles_per_Gallon',
text=alt.condition(highlight, 'Acceleration:Q', alt.value('')),
)
(mpg+text_mpg)|(acc+text_acc)
Demo:
Expected Output:
Show tooltips instead of text, with multiple encodings
I am however starting to feel that this is not the intended behavior of tooltip.

Bumbling around plotting two sets of seasonal data on the same chart

I have series of monthly inventory data since 2017.
I have a series of inventory_forecasts since Dec2018
I am trying to plot the inventory data on a monthly-seasonal basis, and then overlay the inventory_forecasts of Jan2019 through Dec2019.
The dataframe looks like:
The first way I tried to make the chart does show all the data I want, but I'm unable to control the color of the inventory_zj line. Its color seems to be dominated by the color=year(date):N of the alt.Chart I configured. It is ignoring the color='green' I pass to the mark_line()
base = alt.Chart(inv.loc['2000':].reset_index(), title=f"usa total inventory").mark_line().encode(
x='month',
y="inventory",
color="year(date):N"
)
#this ignores my 'green' color instruction, and marks it the same light blue 2019 color
joe = base.mark_line(color='green').encode(
alt.Y('inventory_zj', scale=alt.Scale(zero=False), )
)
base+joe
I tried to use a layering system, but it's not working at all -- I cannot get it to display the "joe" layer
base = alt.Chart(inv.loc['2000':].reset_index(), title=f"usa total inventory").encode(
x='month(date)'
)
doe = base.mark_line().encode(
alt.Y('inventory', scale=alt.Scale(zero=False), ),
color="year(date):N"
)
joe = base.mark_line(color="green").encode(
alt.Y('inventory_zj', scale=alt.Scale(zero=False), ),
)
#looks identical to the first example
alt.layer(
doe, joe
).resolve_scale(
y='shared'
).configure_axisLeft(labelColor='black').configure_axisRight(labelColor='green',titleColor='green')
#independent shows a second y-axis (which is different from the left y-axis) but no line
alt.layer(
doe, joe
).resolve_scale(
y='independent'
).configure_axisLeft(labelColor='black').configure_axisRight(labelColor='green',titleColor='green')
I feel like i must be trying to assemble this chart in a fundamentally wrong way. I should be able to share teh same left y-axis, have the historic data colored by its year, and have a unique color for the 2019-forecasted data. But I seem to be making a mess of it.
As mentioned in the Customizing Visualizations docs, there are multiple ways to specify things like line color, with a well-defined hierarchy: encodings override mark properties, which override top-level configurations.
In your chart, you write base.mark_point(color='green'), where base contains a color encoding which overrides the mark property. If you don't derive the layer from base (so that it does not have a color encoding), then the line will be green as you hoped. Something like this:
base = alt.Chart(inv.loc['2000':].reset_index(), title=f"usa total inventory")
inventory = base.mark_line().encode(
x='month',
y="inventory",
color="year(date):N"
)
joe = base.mark_line(color='green').encode(
x='month',
y=alt.Y('inventory_zj', scale=alt.Scale(zero=False))
)
inventory + joe

How to encircle Invalid data in Excel?

I want to show a circle around only invalid data.
i have done the complete steps shown in this link
But this circle shown is very big and covers the entire cell.
I want a small circle only covering the data not the entire cell's width.
Data validation is a built in Excel functionality. It checks whole cell value.
So it is not possible, using Data validation, to accomplish what your trying.
It MAY BE POSSIBLE using VBA, shapes, events and (hard) parsing character rendering. In your place, I would be glad with this very big circles!!! :)
I agree with #LS_dev. See this MS Article about changing data validation for printing. Try modifying it to loop through all your data validation and change the width and height.
You can probably do it with this part of the code by changing the width and height:
If Not c.Validation.Value Then
Set o = ActiveSheet.Shapes.AddShape(msoShapeOval, _
c.Left - 2, c.Top - 2, c.Width + 4, c.Height + 4)
o.Fill.Visible = msoFalse
o.Line.ForeColor.SchemeColor = 10
o.Line.Weight = 1.25

How do I change the amount of whitespace between sections in Latex?

How do I modify the distance between the end of a section and the header of the next section in a Latex document?
You can configure the style of section headings, including spacing, using the titlesec package. There's a 'compact' option for simple reduction of space, or you can specify specific values using the more advanced options (see the documentation on the linked page for the gory details).
An alternative to titlesec is to redefine the section command, as in the following snippet. Note that beforeskip and afterskip are the variables you're interested in. The code itself is just the first few lines. It's followed by a lengthy comment to remind me of the definitions when I cut and paste the whole thing from one document to another. The code, by the way, is more or less from the indispensable book, The LaTeX Companion, Second Edition.
\makeatletter
\renewcommand\section{\#startsection {section}{1}{\z#}%
{-2.5ex \#plus -1ex \#minus -.2ex}%
{1.3ex \#plus.2ex}%
{\centering\bfseries}}
% \#startsection {NAME}{LEVEL}{INDENT}{BEFORESKIP}{AFTERSKIP}{STYLE}
% optional * [ALTHEADING]{HEADING}
% Generic command to start a section.
% NAME : e.g., 'subsection'
% LEVEL : a number, denoting depth of section -- e.g., chapter=1,
% section = 2, etc. A section number will be printed if
% and only if LEVEL gt or eq the value of the secnumdepth
% counter.
% INDENT : Indentation of heading from left margin
% BEFORESKIP : Absolute value = skip to leave above the heading.
% If negative, then paragraph indent of text following
% heading is suppressed.
% AFTERSKIP : if positive, then skip to leave below heading,
% else - skip to leave to right of run-in heading.
% STYLE : commands to set style
% If '*' missing, then increments the counter. If it is present, then
% there should be no [ALTHEADING] argument. A sectioning command
% is normally defined to \#startsection + its first six arguments.
\makeatother

Resources